1

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?

qadenza
  • 9,025
  • 18
  • 73
  • 126

1 Answers1

5

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

Joseph_J
  • 3,654
  • 2
  • 13
  • 22
  • please read my question again. I don't need to create any image, but get the info of existing ones. – qadenza Apr 07 '18 at 08:32
  • @bonaca That's exactly what this does. But it's only available in PHP 7 >= 7.2.0 "If none of the optional parameters is given, the current resolution is returned as indexed array. " – Joseph_J Apr 07 '18 at 08:34
  • my php is 7.0.20 and using `print_r(imageresolution($item));` result is error - ` Call to undefined function` – qadenza Apr 07 '18 at 08:38
  • is $item a an image object? Let me update my answer. – Joseph_J Apr 07 '18 at 08:39
  • If you're using PHP 7.0, then the function won't be available - as the answer says, it's only in PHP 7.2 (with the GD library enabled) – iainn Apr 07 '18 at 08:42
  • @iainn, I will update my php version. How to enable GD? – qadenza Apr 07 '18 at 08:44
  • @bonaca It'll depend on your OS - see https://stackoverflow.com/questions/2283199/enabling-installing-gd-extension-without-gd for a few pointers, but Google will be able to help – iainn Apr 07 '18 at 08:48