Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
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:
Comment | File | Size | Author |
---|---|---|---|
#7 | imagecache_355230.patch | 2.5 KB | drewish |
#6 | imagecache-rotation_transparency2.patch | 1.81 KB | kirie |
imagecache-rotation_transparency.patch | 1.81 KB | dman |
Comments
Comment #1
dman CreditAttribution: dman commented(whoops, needed doc format to embed this sample img)
Comment #2
drewish CreditAttribution: drewish commentedcould we just use an empty string? i'd be okay with an update function that checked the actions and migrated the values...
Comment #3
dman CreditAttribution: dman commentedEither 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 :-)
Comment #4
drewish CreditAttribution: drewish commentedi 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.
Comment #5
mcjim CreditAttribution: mcjim commentedI 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.
Comment #6
kirie CreditAttribution: kirie commentedI 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).Comment #7
drewish CreditAttribution: drewish commentedI 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.
Comment #8
drewish CreditAttribution: drewish commentedcommitted that to HEAD and DRUPAL-5--2. probably need to clean up the actions some more but that can be follow up.
Comment #10
afox CreditAttribution: afox commentedHey, 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?
Comment #11
kevster CreditAttribution: kevster commentedYes - 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?
Comment #12
Nchase CreditAttribution: Nchase commentedsome 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.
Comment #13
kevster CreditAttribution: kevster commentedThanks 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
Comment #14
fizk CreditAttribution: fizk commentedMarking as ImageCache 3.x Todo.