Changing image resolution from 72 to 25 dpi in PHP

I want to change the image resolution from 72 to 25 dpi using PHP?

Is it possible?

Hi,

Salil Gaykvad

+4
source share
3 answers

This is not possible (at least with PHP / GD, not sure about ImageMagik), sorry.

However, you can try to simulate it, let's say you want to create a 400x300 image of 25 dpi , 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 image 139x104 72 dpi , work with it and after you make its size up to 400x300 pixels.

+3
source

Using ImageMagick :

 $img = new Imagick(); $img->setResolution(25,25); 
+3
source

Use the code line below to convert images with a resolution of 72 to 25 dpi:

$ filename = "Enter the path to the image 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); 
0
source

Source: https://habr.com/ru/post/1299173/


All Articles