Skip to content

imageresolution Return incorrect DPI #10351

@ve3

Description

@ve3

Description

The following code:

<?php
$fullPathNewFileName = '772.jpg';
$img = imagecreatefromjpeg($fullPathNewFileName);
$result = imageresolution($img);

var_dump($result);

Resulted in this output:

array(96, 96)

But I expected this output instead:

array(240, 240)

You may test with this jpeg file in zip.
https://gofile.io/d/IiGLN1
or alternative link https://fromsmash.com/sample-jpeg-for-php-get-resolution

Not all images are detected DPI correctly. Only some images are unable to detect and return 96 DPI.

This happens since PHP 7 but PHP 8.2 still occur.

If I use Imagick on PHP 8.1 or any version, it returns correct resolution.

$Img = new Imagick($fullPathNewFileName);
$result = $Img->getImageResolution();

var_dump($result);// array('x' => 240, 'y' => 240)

PHP Version

PHP 8.2.0

Operating System

Windows 11 x64

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions