Issues with very high DPI PDFs

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
nickwest
Posts: 1
Joined: 2019-04-08T15:12:10-07:00
Authentication code: 1152

Issues with very high DPI PDFs

Post by nickwest » 2019-04-08T15:32:28-07:00

When trying to open a very high DPI (1200 in this case) PDF PHP uses a full CPU core until timeout regardless of file size or complexity of the PDF. This happens on construct of the imagick object before I can check the PDF dimensions.

To replicate make a 10200x13200 gray square in sketch (or your app of choice) and export to PDF. The file will be small (<10kb) but IMagick can't load it in a reasonable amount of time.

Here's the code I used to test:

Code: Select all

$im = new \imagick('/path/to/file.pdf');
$properties = $im->identifyImage();
I timeout while processing the first line. I'm looking for a work around that would let me get the resolution of the PDF before I try to open it so I can prevent a PHP timeout. The PDFs I'm processing are uploaded by end-users. I restrict file size (3MB in this case), page size (8.5" x 11"), and page count (1). I get the file size from the POST, but page size and count I'm getting with IMagick.

The problem being that a high resolution low file size PDF will simply timeout. Does anyone know of a solution for this?

User avatar
fmw42
Posts: 25135
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Issues with very high DPI PDFs

Post by fmw42 » 2019-04-08T15:44:43-07:00

When you use a large density value, the PDF gets rasterized by Ghostscript to a very large image once loaded. Make sure you have enough RAM or set your ImageMagick environment variables map and memory limits to allow the file to page to disk. See https://imagemagick.org/script/resource ... nvironment

Please always provide your IM version and platform/OS. Also check your version of Ghostscript.

Post Reply