-
Notifications
You must be signed in to change notification settings - Fork 735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
getimagesize() does not account for EXIF orientation #2745
Comments
getimagesize will report the dimensions of the actual image data. This will not account for an image that has an orientation set in the EXIF data - which is common for photos from a smartphone held horizontally. Please check that the image you're working with doesn't have such an orientation. With PHP, you can use exif_read_data. Otherwise, there are a variety of image tools and editors which can tell you about image orientation. |
This was fantastic, thank you! |
Actually, let's keep this open: getimagesize ought to have some note about image orientation, like it already does about things like bit depth and animated GIFs. |
@damianwadley -- can you point to (or give) an example of how to use |
@jimav I believe there are a few user comments on the documentation page for exif_read_data that show how. |
To get the actual orientation, you can use something like: if (($exif = exif_read_data($filename))) {
$orientation = $exif["Orientation"] ?? 0;
} else {
$orientation = 0;
} If (Proper handling for GD is a bit more contrieved, but is doable, but this would be off-topic here.) |
From manual page: https://php.net/function.getimagesize
I believe the return array indices 0 and 1 are intended to be reversed.
Currently, index 0 is returning image height, while index 1 is returning image width.
I believe that index 3 is expecting the same logic reversal, as it produces a string "width="[0]" height="[1]"" -- the height value is being printed in the width attribute and the width value is being printed in the height attribute.
The text was updated successfully, but these errors were encountered: