Change resolution of image from 72 to 25 dpi in PHP
I want to开发者_开发知识库 change the resolution of the image from 72 to 25 dpi using PHP?
is it possible?
Regards,
Salil Gaikwad
It's not possible (at least with PHP/GD, not sure about ImageMagik), sorry.
However you can try mimicking it, lets say you want to create a 400x300 25 dpi image, here is the math:
WIDTH
72 -------- 400
25 -------- w = (25 * 400) / 72 (=) w ~= 139 pixels
HEIGHT
72 -------- 300
25 -------- h = (25 * 300) / 72 (=) h ~= 104 pixels
You create a new 139x104 72 dpi image, work with it and after you're done resize it to 400x300 pixels.
Using ImageMagick:
$img = new Imagick();
$img->setResolution(25,25);
Use below line of code to convert image dpi from 72 to 25 dpi :
$filename = "Enter path of the image which you want to use";
$image = file_get_contents($filename);
$image = substr_replace($image, pack("cnn", 1, 25, 25), 13, 5);
file_put_contents($filename,$image);
精彩评论