For some reason imageapi_gd_image_rotate() inverts the degree of rotation in the call to imagerotate(). I've only tested this on versions of PHP without imagerotate() (Debian), so I can't verify whether it's required to invert the number of degrees in the version of GD bundled with PHP where imagerotate() is present.

Anyway, this simple one-liner fixes this.

Comments

drewish’s picture

you're sure the problem is not with the code for rotation when gd's rotate isn't available?

kaare’s picture

StatusFileSize
new1.45 KB

imagerotate() in imagerotate.inc is working as expected without inverting the degree for any angle except 90 and 270. The shorthand rotation techniques for 90 and 270 were swapped. New patch attached. Swapping between toolkits gives the same result, except the imagerotate.inc version is a bit rough around the edges for non 90° angles ;-)

And I haven't got access to any php installations with GD's imagerotate() available, unfortunately.

drewish’s picture

StatusFileSize
new873 bytes

I just double checked that both GD and ImageMagick rotate the correct directions. So it sounds like it's our PHP implementation that's to blame.

Applying your patch reversed the rotation for GD.

The attached works for both GD and ImageMagick.

kaare’s picture

StatusFileSize
new683 bytes

I had to compile php with the bundled version of gd myself to experiment with imagerotate(). And indeed, imagerotate() in GD bundled with php-5.2.6 rotates images counterclockwise. I believe it's the case also for php-5.2.8. I took a diff in the php-5.2.X/ext/gd directories and found no indication that it has been fixed.

Anyway, this patch inverts the angle in imagerotate() in imagerotate.inc so the implementations behave the same and the invertion in imageapi_gd_rotate() work for both versions.

drewish’s picture

Status: Needs review » Fixed

committed to HEAD and DRUPAL-6--1

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

kaare’s picture

Title: gd_rotate() rotate wrong way » gd_rotate() rotate wrong way for 90° and 270°
Status: Closed (fixed) » Needs review

The image still rotates the wrong way for 90° and 270°. Your patch in #3 is still required to fix the rotation in the php implementation.

Took me a year to figure this one out ;-)

drewish’s picture

Status: Needs review » Fixed

nope, that code has been committed. it just looks like it was never rolled into a release.

David Stosik’s picture

Status: Fixed » Active

Image API GD is still rotating my images the wrong way for 90° and 270°. Using Ubuntu 10.04, with PHP 5.2 backport, and php-gd is installed.
Tried 270, 90 and 45 : only 45° is rotated the right way.
I just downloaded all the modules implied (ImageAPI, Imagefield, Imagecache).
Trying to remove the "360 - " in the call to imagerotate() fixes my problem.

Any hint anyone ?

Thanks,

David

drewish’s picture

David Stosik, which version are you using?

David Stosik’s picture

Image API 6.x-1.8
ImageCache 6.x-2.0-beta10
PHP 5.2.10

I just downloaded all of these yesterday.

dman’s picture

ImageAPI DRUPAL-6--1-8 CVS
Imagecache DRUPAL-6--2-0-BETA10 CVS
GD bundled (2.0.34 compatible)
PHP 5.2.11

.. I'm not seeing this. a 90' and a 91' imagecache preset are both rotated clockwise for me.

David Stosik’s picture

Drupal status page tells me GD does not support rotation. I suppose ImageAPI GD is using its bundled function instead...

kaare’s picture

dman, your version of gd is the one bundled with php. This issue is now regarding the version of php compiled without the bundled gd package, as it is in debian and ubuntu. These will trigger the usage of imagerotate() from the included file imagerotate.inc in this project. And this version works for all cases except 90° and 270°.

I did some testing using imagecache with a single rotate action and got these results using this image.

Unpatched:

80° 90° 100° 260° 270° 280°

With Drewish's patch from #3

80° 90° 100° 260° 270° 280°

Drewish, you may have misunderstood me earlier. Your patch in comment #3 is still required for the non-bundled version of gd to work properly. The original patch for this issue and my patch in #4 is applied an lives well, but imageapi_gd still fails for 90° and 270° on debian/ubuntu until #3 also is applied.

kaare’s picture

The attach/list behavior is awkward.. Anyway. See attachments for the rendered images both unpatched and patched.

kaare’s picture

StatusFileSize
new48.38 KB
new44.52 KB
new48.31 KB

Forgot 260, 270, 280, unpatched.

David Stosik’s picture

This issue is now regarding the version of php compiled without the bundled gd package, as it is in debian and ubuntu.

Yes, I am using Ubuntu. :)

Drewish's #3 patch seems to be the solution. :)

Thanks fo the follow up.

drewish’s picture

Status: Active » Fixed

Great, thanks for all the testing. Committed to HEAD and DRUPAL-6--1.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.