qadenza
qadenza

Reputation: 9293

get and set image dpi

I need some info about images inside cardimg folder.

$arr = glob("../cardimg/*.jpg");
foreach ($arr as $item){
    list($width, $height) = getimagesize($item);
    echo $width . '<br>';
    echo $height . '<br>';
}

Works fine for width and height, but don't know how to see if an image is 72 or 300 dpi?

my php is 7.0.20 and using

print_r(imageresolution($item));

result is error - Call to undefined function

Also is there a way to change 300dpi to 72dpi using php?

Upvotes: 1

Views: 3028

Answers (1)

Joseph_J
Joseph_J

Reputation: 3669

This is straight from PHP.net for imageresolution(). (PHP 7 >= 7.2.0)

<?php
$im = imagecreatetruecolor(100, 100);
print_r(imageresolution($im));
imageresolution($im, 300, 72);
print_r(imageresolution($im));
?>

This should get you what you need once you update your php version:

$im = imagecreatefromstring(file_get_contents($path));
print_r(imageresolution($im));
imagedestroy($im);

Here is a link on how to get gd library up and going.. I'm sure this varies on server setup hosted or not, I don't know. But should help I imagine.

Enable GD support in PHP

Upvotes: 5

Related Questions