|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #66516 getimagesize() should cater to orientation flag
Submitted: 2014-01-19 16:01 UTC Modified: 2016-10-07 22:38 UTC
Avg. Score:3.7 ± 0.9
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:0 (0.0%)
From: milpas999 at gmail dot com Assigned:
Status: Re-Opened Package: GetImageSize related
PHP Version: Irrelevant OS: windows 8.1
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
10 + 46 = ?
Subscribe to this entry?

 [2014-01-19 16:01 UTC] milpas999 at gmail dot com
My objective is to upload an image and then to create a new image with some other 'width X height' resizing parameters. Original image has uploaded successfully, but when i am using getimagesize('local path of original uploaded image') it is returning wrong values.

And this function is not working only for images of dimension '1836 X 3264' 

original image dimension : 1836 X 3264
and when using getimagesize() for the image it returns

    [0] => 3264
    [1] => 1836
    [2] => 2
    [3] => width="3264" height="1836"
    [bits] => 8
    [channels] => 3
    [mime] => image/jpeg

Same as  Bug #29424. but i am unsing PHP 5.4.3 and bug reporter was using PHP 5.0.0

Test script:
$source_image_path = '../sysimages/origimage/20131109_151445.jpg';

$arrrrr = getimagesize($source_image_path);

print("<pre>arrrrr :: ");

Expected result:
    [0] => 1836
    [1] => 3264
    [2] => 2
    [3] => width="1836" height="3264"
    [bits] => 8
    [channels] => 3
    [mime] => image/jpeg

Actual result:
    [0] => 3264
    [1] => 1836
    [2] => 2
    [3] => width="3264" height="1836"
    [bits] => 8
    [channels] => 3
    [mime] => image/jpeg


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-01-19 16:11 UTC]
-Status: Open +Status: Feedback
 [2014-01-19 16:11 UTC]
Please provide a link to the image you use.

There is certainly a rotation/orientation meta data which makes some application automatically rotate the image on load.
 [2014-12-30 10:42 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 [2015-09-12 11:23 UTC] nicolas33thomas at gmail dot com
I have the same issue with PHP 5.4.12.

It looks to mainly happen with pictures taken with a smartphone.

Here is the picture:

Note that this picture has been resampled.

Here is the original one:

I tried with it, and I get inverted width and height value too.
 [2015-09-12 13:50 UTC]
-Status: No Feedback +Status: Re-Opened -Type: Bug +Type: Feature/Change Request
 [2015-09-12 13:50 UTC]
> Here is the original one:
What @pajoye said is correct: the image itself is sideways but the camera added EXIF data that specifies the "correct" orientation. GIMP, for one, presents a dialog to that effect when you try to open the file.
Since getimagesize() is behaving the way it was intended to, I'm changing this to a feature request.

If it returned the re-oriented dimensions then that could cause problems if code relies on them while trying to process the image. Maybe it could continue returning the true dimensions but also include a new value in the array indicating the orientation?

However the exif extension is also available to handle this kind of problem. See some of the user comments in the exif_read_data() doc for examples:
 [2015-09-12 15:39 UTC] nicolas33thomas at gmail dot com
Ok, I understand now.
It makes sense.

So if my picture has exif data, I will rely on them, otherwise, I will take the getimagesize result as it is.

Thank you for your quick reply.
 [2016-10-07 22:38 UTC]
-Summary: getimagesize() function is returning swaped values of height and width. +Summary: getimagesize() should cater to orientation flag
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 14 12:01:28 2024 UTC