Bug #77052 [Opn->Fbk]: imagescale() rotates image anti-clockwise by 90 degree after scaling

From: Date: Wed, 24 Oct 2018 05:42:30 +0000
Subject: Bug #77052 [Opn->Fbk]: imagescale() rotates image anti-clockwise by 90 degree after scaling
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-217672@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77052&edit=1

 ID:                 77052
 Updated by:         requinix@php.net
 Reported by:        hyh19962008 at gmail dot com
 Summary:            imagescale() rotates image anti-clockwise by 90
                     degree after scaling
-Status:             Open
+Status:             Feedback
 Type:               Bug
 Package:            GD related
 Operating System:   Windows Server 2012 R2
 PHP Version:        7.2.11
 Block user comment: N
 Private report:     N

 New Comment:

The image you expect to see is not the actual image. It has been rotated for viewing according to
EXIF data embedded in the file. You must read that orientation data to determine the
"correct" image alignment, then base your rotation accordingly.
https://www.google.com/search?q=php+exif+image+orientation


Previous Comments:
------------------------------------------------------------------------
[2018-10-24 04:30:32] hyh19962008 at gmail dot com

Description:
------------
When scaling an image using the GD function imagescale(), the image is rotated anti-clockwise by 90
degree automatically.

This happens most frequently when the given image has a greater height than width, and was shot by
camera or mobile.

Test script:
---------------
<?php
	$filename="C:\inetpub\wwwroot\\apc\\img\\1.JPG";
	$pic=imagecreatefromjpeg($filename);
	$ratio=imagesy($pic)/imagesx($pic);		//=height/width
	$height=136;
	$width=136/$ratio;
	$pic=imagescale($pic,$width,$height);
	imagejpeg($pic,"min//1.jpeg",86);
	imagedestroy($pic);
?>

Expected result:
----------------
image with the following w/h

width=136/ratio;
height=136;

height is greater than width, the image should be presented vertically.

Actual result:
--------------
image with the following w/h

width=136;
height=136/ratio;

width is greater than height, the image is presented horizontally, because it's rotated
anti-clockwise by 90 degree comparing to the original image.

I have uploaded the script and sample picture to my website:
https://www.swuplaf.cn/abc/test.php    //script
https://www.swuplaf.cn/abc/img/1.JPG   
//original picture
https://www.swuplaf.cn/abc/min/1.jpeg   
//scaled picture



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=77052&edit=1


Thread (4 messages)

« previous php.bugs (#217672) next »