I am using jMagick for java to process uploaded files (images and pdf files). Most images work fine but when I tried to convert large multiple-page pdf files to different size of images, it consumes very large amount of system memory (about 20G physical memory for a 200M pdf files), and failed eventually. I am setting the density to 200 since otherwise the image quality is very bad that I cannot even read the words in the output images. Below is the code I have:
ImageInfo info = new ImageInfo(inputFilePath);
info.setDensity(200);
MagickImage image = new MagickImage(info);
MagickImage[] imageFrames = image.breakFrames();
for (MagickImage frame : imageFrames) {
ImageInfo frameInfo = new ImageInfo();
MagickImage frameDisplay = frame;
frameDisplay.setFileName(outputFile);
frameDisplay.writeImage(frameInfo);
}
There is no error or exception in my java log, I just see the process died. I have tried to use policy.xml in /usr/share/ImageMagick-6.5.4/config/ to limit the memory usage as follows:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policymap [
<!ELEMENT policymap (policy)+>
<!ELEMENT policy (#PCDATA)>
<!ATTLIST policy domain (delegate|coder|filter|path|resource) #IMPLIED>
<!ATTLIST policy name CDATA #IMPLIED>
<!ATTLIST policy rights CDATA #IMPLIED>
<!ATTLIST policy pattern CDATA #IMPLIED>
<!ATTLIST policy value CDATA #IMPLIED>
]>
<policymap>
<policy domain="resource" name="memory" value="256MB"/>
</policymap>
But somehow it does not seem to work. I am using ImageMagick-6.5.4. Really appreciate any advice!