In the D5 version (IIRC) it was possible to set the background color to -1 which would be passed through to the rotate function and make the surrounding area transparent. This doesn't work in the current D6 version.
Here is a patch that re-instates that behaviour.

Of course, it's not very effective with just jpegs, but helps a lot with PNGs and the imagecache_actions pipeline.

Here's a patch which seems to do the trick, including a small explanation in the UI.
Without it, I can't do things like:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dman’s picture

(whoops, needed doc format to embed this sample img)

drewish’s picture

could we just use an empty string? i'd be okay with an update function that checked the actions and migrated the values...

dman’s picture

Either is good.
I just saw that -1 was already established as the constant in PHP core docs, so didn't think it needed abstracting.

For most users, I'm guessing that pre-populating the form with #FFFFFF is desired anyway, and would be a UI help.
Consciously deleting it, with the effect being documented, would be OK and not create surprises.

More than anything, I just wanted a simple patch to avoid changing that code/logic more than was necessary. Which is not an excuse for not actually improving it :-)

drewish’s picture

Status: Needs review » Needs work

i think you're right to leave white as the default but i'd prefer not to use -1, i think an empty value is much clearer to the user that they want no color.

mcjim’s picture

I tried this out and found I had to add:

imagesavealpha($image->res, TRUE);

before the final return true; to keep the alpha transparency. Does that seem right? First time I've messed with this image manipulation stuff, so a little unsure here.

Agree that an empty value would be better than -1: other imagecache actions use an empty value.

kirie’s picture

Status: Needs work » Needs review
FileSize
1.81 KB

I got some errors when I tried to apply this, and figured out it was caused by some internal imagecache property renaming: $image->res is now $image->resource. I edited the patch above and attached it (I also changed '-1' to empty as per above comments).

drewish’s picture

FileSize
2.5 KB

I marked #434476: imagecache_rotate action produces jagged lines and black background as a duplicate of this.

Over on #422836: ImageAPI GD2 6.x-1.5 ignores crop background color setting I fixed and ImageAPI bug that wasn't passing the background colors through. The attached patch uses NULL as per the new ImageAPI release.

drewish’s picture

Status: Needs review » Fixed

committed that to HEAD and DRUPAL-5--2. probably need to clean up the actions some more but that can be follow up.

Status: Fixed » Closed (fixed)

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

afox’s picture

Status: Closed (fixed) » Needs work

Hey, I'm using the latest Imagecache dev(2009-Oct-09) and this issue is still on it! I made sure that the patch was committed, but I'm still having black background on a transparent png when rotating.

Running Core D6.15

Anyone else still having this issue?

kevster’s picture

Yes - still having this problem, have tried the above patch but didn't work for me? I might try an earlier version as the patch differs from the code I have. Weird as we had this working at one point and not sure how it broke...

working off imagecache 6.x-2.0-beta10...

Did you have any luck yet?

Nchase’s picture

some time ago I had the same problems... It was an error from the gd library... using different libraries results in different images, once with correct transparency once with a background...

the second thing was using jpg's.. I had to convert them to pngs first and then applying the rotation.

kevster’s picture

Thanks for the advice snicers - when I checked the dupal settings for GD library it said there may be problems with image rotation. We will look at updating/reinstalling GD libs and see if that helps. I have been converting to PNG first but no change.

Thx - Kevin

fizk’s picture

Issue tags: +ImageCache 3

Marking as ImageCache 3.x Todo.