Change DPI + resample
Posted: 2014-02-14T01:44:27-07:00
I'm trying to change the DPI and of an image to make the output the same as when I change the DPI in Photoshop. I already got it working with ImageMagick, but now I want it to work with Imagick as well. I have to change the DPI of the input image to 100 (because I need to print it).
My input image has these specifications (Photoshop):
Width: 700px
Height: 500px
Document size:
Width: 18,52 cm
Height: 13,23 cm
Resolutation (DPI): 96
My output image has these specifications (using ImageMagick and Imagick and Photoshop to open them again):
Output ImageMagick:
Width: 729px
Height: 521px
Document size:
Width: 18,52 cm
Height: 13,23 cm
Resolutation (DPI): 100
Output Imagick:
Width: 700px
Height: 500 px
Document size:
Width: 17,78 cm
Height: 12,70 cm
Resolutation (DPI): 100
This is the code I'm using with ImageMagick (PHP):
And this is the code I'm using with Imagick:
So its changing my cm and not my px. How do I get the exact same output with Imagick?
My input image has these specifications (Photoshop):
Width: 700px
Height: 500px
Document size:
Width: 18,52 cm
Height: 13,23 cm
Resolutation (DPI): 96
My output image has these specifications (using ImageMagick and Imagick and Photoshop to open them again):
Output ImageMagick:
Width: 729px
Height: 521px
Document size:
Width: 18,52 cm
Height: 13,23 cm
Resolutation (DPI): 100
Output Imagick:
Width: 700px
Height: 500 px
Document size:
Width: 17,78 cm
Height: 12,70 cm
Resolutation (DPI): 100
This is the code I'm using with ImageMagick (PHP):
Code: Select all
exec("convert -strip -units PixelsPerInch input.jpg -resample 100 -set density 100 output.jpg");
Code: Select all
$img = new Imagick('input.jpg');
$img->stripImage();
$img->setImageUnits(imagick::RESOLUTION_PIXELSPERINCH);
$img->setImageResolution(100,100);
$img->resampleImage(100,100,imagick::FILTER_UNDEFINED,1);
$img->writeImage('output.jpg');
$img->destroy();