I defined a rotate effect with an empty background. According to the on-screen help and the GD implementation this should give me a transparent background (in the corner triangles). however the imagick toolkit results in an image with the triangles coloured according to the cornel pixel colors.

I fixed this as below in the given function. Note that in that function there were also references to the not initialized variable $bgcolor whereas $background (the parameter) should have been used.

file: imageapi_imagemagick.module
function: image_imageapi_imagemagick_rotate
new code:


function image_imageapi_imagemagick_rotate(stdClass $image, $degrees, $background = NULL) {
  if (is_null($background)) {
    $bgcolor = 'transparent';
  } elseif (is_int($background)) {
    $bgcolor = '#'. str_pad(dechex($background), 6, 0);
  } else {
    $bgcolor = str_replace('0x', '#', $background);
  }
  $image->ops[] = '-background '. escapeshellarg($bgcolor) .' -rotate '. (float) $degrees;
  return TRUE;
}

Perhaps the literal string transparent should be replaced by something like rgba(0,0,0,0.0) as I'm not sure that transparent will be defined (in colors.xml) in all (supported) installations/versions.

CommentFileSizeAuthor
#4 1021850-4.patch1.22 KBfietserwin
#1 1021850.patch901 bytesfietserwin

Comments

fietserwin’s picture

StatusFileSize
new901 bytes

And as a patch (against the 7.x-1.x-dev 2010-Oct-18 version).

sun’s picture

Title: imagick toolkit: rotate with empty background color does not yield a transparent background » Rotate with empty background color does not yield a transparent background
Project: ImageAPI » ImageMagick
Component: ImageAPI Imagick » Code
Status: Active » Needs work
fietserwin’s picture

Status: Needs work » Fixed

Looks like it has been added to the dev version?!

fietserwin’s picture

Status: Fixed » Needs review
StatusFileSize
new1.22 KB

The "-background transparent" option is necessary as actions earlier on the command line may already have used the -background option. Thus the original code works better in combination with other commands.

sun’s picture

This looks good. I merely wonder what happens if the image format doesn't support transparency? Or do we simply don't care about that and leave it to effect configuration to figure out?

fietserwin’s picture

Well, the background color is entered by the user/admin defining the style. We may assume that (s)he knows what (s)he's doing and doesn't fill in transparent (or leaves the field empty) with, e.g., a jpg format. Thus I think we shouldn't care (as imagemagick also doesn't).

sun’s picture

Status: Needs review » Fixed

Thanks for reporting, reviewing, and testing! Committed and pushed to 7.x-1.x.

A new development snapshot will be available within the next 12 hours. This improvement will be available in the next official release.

Status: Fixed » Closed (fixed)

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