Rather than rendering and then resizing the raster, it might be better to render the PDF to the right number of pixels in the first place. It'll be faster, and you can be sure that the amount of sharpness is correct for the content.
$ time convert -density 50 ksgt-06-04-1091539.pdf x2.png real 0m0.325s user 0m0.299s sys 0m0.024s
-density 50 makes a page about the same number of pixels across as your sample, 425.
In imagick you could do it like this (as @fmw42's excellent answer already says):
#!/usr/bin/env php <?php $target_width = 400; # get natural size, calculate density we need for target width $im = new imagick(); $im->pingImage($argv); $geo = $im->getImageGeometry(); $natural_width = $geo['width']; $density = 72.0 * $target_width / $natural_width; # load at correct resolution for target_width $im = new imagick(); $im->setResolution($density, $density); $im->readImage($argv); # and write back $im->writeImage($argv);
Doing both the ping and the read is a little slow in imagick, unfortunately:
$ time ./pdfthumb.php ksgt-06-04-1091539.pdf x.png real 0m2.773s user 0m2.737s sys 0m0.036s
It's not imagick, but
vipsthumbnail can do the ping and read in one operation:
$ time vipsthumbnail ksgt-06-04-1091539.pdf -s 400x -o x2.png real 0m0.064s user 0m0.064s sys 0m0.011s
It might be worth considering if speed is important. libvips has a php binding so you can call it directly, but if you do that you'll run into awful licensing problems because it uses the GPL library poppler for PDF rendering, sigh. ImageMagick uses GhostScript and shells out to that for the same reason.