How to resize an image using PHP while retaining the resolution?

advertisements

I'm wondering if there's a way to resize a batch of images using a library such as GD or ImageMagick to resize an image down while retaining its resolution?

Currently, I am starting with a very large image (roughly 3500 X 2400 @ 300ppi) when I try to resize images down (to around 1000 X 775), I get a large image in the right dimensions, but the resolution drops to 72ppi (confirmed by photoshop).

$im = new Imagick();
//Initial resolution of image
$im->setResolution(300,300);

$im->readImage('mypdf.pdf');
$im->adaptiveResizeImage(707,1000);

I've also used:

$image->resizeImage(707,1000, imagick::FILTER_LANCZOS, 0.9, true);

But the result ends up being pretty much the same. Thanks in advance. Any suggestions welcome.

After reading the suggestions here is how my code looks like right now

$im = new Imagick();
$im->setResolution(300,300);

$im->readImage('mypdf.pdf');
$im->setImageUnits(imagick::RESOLUTION_PIXELSPERINCH);
$im->adaptiveResizeImage(707,1000);
$im->setResolution(300,300);
$im->setImageFormat( "jpg" );
$originalImageFile = 'myjpg.jpg';
$im->writeImage($originalImageFile);$im->setResolution(300,300);

The output image has a very low quality, here is how it looks like

http://i46.tinypic.com/ehfyf8.jpg


Check out the first comment here:

http://php.net/manual/en/imagick.setresolution.php

In addition to setting the resolution you must also set the resolution units:

$im->setImageUnits(imagick::RESOLUTION_PIXELSPERINCH);