In imageapi_imagemagick_image_rotate() the parameter pipeline for rotating an image is in the wrong order. ImageMagick (6.3.X, and I believe the entire 6.X series) needs the -background parameter before -rotate.

In addition, the type testing for color value need to be test for integer, not numeric as dechex() will fail on string values (or always set it to 0 = black).

This simple patch cleans this up.

CommentFileSizeAuthor
#3 imageapi_373041.patch944 bytesdrewish
im_rotate_bgcolor.patch655 byteskaare

Comments

drewish’s picture

what about checking for is_numeric() then casting to an int?

kaare’s picture

is_numeric() returns true for all number literals as strings in php. That is, it will return true for all these cases:

  • '123' (decimal)
  • '0x123' (hex)
  • '0123' (oct)
  • '123e4' (123*10^4)
  • '1.23' (float)

This means that the test is_numeric() also accept colors specified as hex string ('0xRRGGBB'). Now, casting this value (same as intval()) will return 0 (This is what PHP does internally with the argument to dechex()). Assuming you know it's a hex string, you can run hexdec(), but there is no point in that, as you want a hex representation of the color as a string.

I'd like to think that if you get a color, and it already is an integer, it's because it has been specified as PHP hex literals or that it already has been run through hexdec(). Is it a string, well, then it's in hex of some sort ('#RGB', '0xRRGGBB', 'RGB').

Now, as the comment in imageapi_image_rotate() says, the color parameter should be a hex integer. If it's a string, everything is ok, just strip the '0x' or '#' part in the beginning. If it's a hex literal as integer, test whether it's an integer and run dechex() and everything is ok.

drewish’s picture

Status: Needs review » Fixed
StatusFileSize
new944 bytes

thanks for clarifying that. committed to HEAD and DRUPAL-6--1. attaching a clean re-roll.

Status: Fixed » Closed (fixed)

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