php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66882 imagerotate by -90 degrees truncates image by 1px
Submitted: 2014-03-11 15:17 UTC Modified: 2015-07-13 20:02 UTC
Votes:4
Avg. Score:3.2 ± 0.4
Reproduced:4 of 4 (100.0%)
Same Version:3 (75.0%)
Same OS:2 (50.0%)
From: jarrod at makin dot co Assigned: cmb (profile)
Status: Closed Package: GD related
PHP Version: 5.5.10 OS: RHEL6.5
Private report: No CVE-ID: None
 [2014-03-11 15:17 UTC] jarrod at makin dot co
Description:
------------
Rotating an image anticlockwise by -90 degrees (clockwise 90 degrees) produces an image that is 1px narrower than you would expect and the left most vertical column of pixels are all black.

However, rotating an image anticlockwise by 270 degrees (also clockwise 90 degrees) produces an image of the correct dimensions and without the line of black pixels.

Test script:
---------------
Source
http://www.jarrodmakin.com/imagerotate.txt

Usable test script
http://www.jarrodmakin.com/imagerotate.php

Expected result:
----------------
Paraphrasing:

Dimensions are A x B
Dimensions of rotation are B x A

Actual result:
--------------
Paraphrasing:

Dimensions are A x B
Dimensions of rotation are B x (A - 1)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-03-12 04:34 UTC] phpmpan at mpan dot pl
Confirmed for master snapshot and 5.5.10.

A quick dive into the code suggests `gmImageRotateBilinear` contains code that handles floats inproperly by casting them to `int` (hence truncating) where extracting integer part was probably meant.

Minimal code:

$image = imagerotate(imagecreate(10, 10), -90, 0)
echo imagesy($image), 'x', imagesx($image)

If the source image has size of 1x1, the effects are even worse, as the functions below receive 0 as size.
 [2014-03-12 04:35 UTC] phpmpan at mpan dot pl
A typo. I meant `gdImageRotateBilinear` of course, not `gm...`.
 [2015-07-12 21:30 UTC] cmb@php.net
Might be a duplicate of bug #65148.
 [2015-07-13 10:39 UTC] jarrod at makin dot co
I agree. I do appear to have reported a duplicate of #65148, the reporter observed that rotations by negative degrees truncated the picture.
I will aim to build up to date php5.4, 5.5 and 5.6 this week and test.
 [2015-07-13 20:02 UTC] cmb@php.net
-Status: Open +Status: Analyzed -Assigned To: +Assigned To: cmb
 [2015-07-13 20:02 UTC] cmb@php.net
The issue is rather clear for square angles. As of PHP 5.5.0 the
rotation is done by gdImageRotateInterpolated()[1], which has
special cases for 90, 180 and 270 degrees, but not for their
negative counterparts. That has already been fixed in the external
libgd by adding special cases for -90, -180 and -270 degress[2].

I'm going to port these changes to PHP's bundled libgd as fix for
this ticket. I'm leaving the other ticket open, because the user
comments seem to refer to non-square angles (at least partially),
and these issues deserve some closer investigation.

[1] <https://github.com/php/php-src/blob/php-5.6.11/ext/gd/libgd/gd_interpolation.c#L2156>
[2] <https://github.com/libgd/libgd/blob/gd-2.1.1/src/gd_interpolation.c#L2219-L2229>
 [2015-07-13 20:34 UTC] cmb@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=php-src.git;a=commit;h=2e34febb733742baf130a9dae4f30f48ffe74d48
Log: Fix #66882: imagerotate by -90 degrees truncates image by 1px
 [2015-07-13 20:34 UTC] cmb@php.net
-Status: Analyzed +Status: Closed
 [2015-07-14 08:14 UTC] cmb@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=php-src.git;a=commit;h=36439cf7b8b00249f8f90be9dabe1e24bbadf7a1
Log: Fix #66882: imagerotate by -90 degrees truncates image by 1px
 [2015-07-21 14:20 UTC] ab@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=php-src.git;a=commit;h=2e34febb733742baf130a9dae4f30f48ffe74d48
Log: Fix #66882: imagerotate by -90 degrees truncates image by 1px
 [2015-07-21 14:20 UTC] ab@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=php-src.git;a=commit;h=36439cf7b8b00249f8f90be9dabe1e24bbadf7a1
Log: Fix #66882: imagerotate by -90 degrees truncates image by 1px
 [2016-07-20 11:37 UTC] davey@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=php-src.git;a=commit;h=36439cf7b8b00249f8f90be9dabe1e24bbadf7a1
Log: Fix #66882: imagerotate by -90 degrees truncates image by 1px
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC