Hello All,Ineed a help in uploading image in which i want that the image which is of 150 dpi(dots per inch ) ,is only upload and smaller den that show messge .My issuue is that how i apply tht :( please give me some direction in tht

4 Years
Discussion Span
Last Post by neha05

If you use Imagick, it has a method to determine resolution. Not sure if GD provides one. Otherwise there's still an option to read it directly from the file (saw an implementation on SO).


thanks for quick reply but i am trying to use formula which dpi=(pixeles of lenght)/inches of lenght

pixles=width *height
and i am confusing in the inches of length is ?? or i am going in ryt direction ?



I think the OP wants to check if a given image matches the minimum print sizes at a defined DPI:


    $image = 'img1.jpg';

    list($w, $h) = getimagesize($image);

    $dpi = 150;

    # current sizes in inches
    $inW = round($w / $dpi, 2);
    $inH = round($h / $dpi, 2);

    # min print sizes in inches
    $printW = 5;
    $printH = 5;

    echo PHP_EOL;

    if($inW >= $printW && $inH >= $printH)
        echo "Correct, the print sizes at {$dpi}DPI are: {$inW} x {$inH} inches";
        echo "This image is too small";

    echo PHP_EOL;

With an image at 1920x1080 the result will be 12.8x7.2 inches. You can get the same result with ImageMagick, as suggested by Pritaeas, for example from the command line:

identify -format "%[fx:w/150] by %[fx:h/150] inches" img1.jpg

Docs: http://www.imagemagick.org/script/identify.php


thanks cereal ,but i am checking this code it echo same size 12.8x7.2 for any image "Correct, the print sizes at {$dpi}DPI are: {$inW} x {$inH} inches";

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.