Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I'd backported the image api changes that were committed to core in #373613: Create "Image" Objects, Operate on Images By Resource to the ImageAPI module. Over in #422836-6: ImageAPI GD2 6.x-1.5 ignores crop background color setting evolvingweb pointed out that you can use the crop to enlarge an image and expose the background which would default to black. We need to add a $background parameter to the image_crop() function to allow the user to specify the color and match up with image_rotate().
Comment | File | Size | Author |
---|---|---|---|
#6 | image_crop_bg.patch | 17.44 KB | drewish |
Comments
Comment #1
Stefan Nagtegaal CreditAttribution: Stefan Nagtegaal commentedThis is a theme dependant color imo, and should be used like that.
If you want to do this right, the only thing you could do is to re-generate the image and have a transparent background which needs:
- your image to be converted to png to allow transluscency (gif isn't reliable when rotating your image if != 90, 180, 270 °C)
Would it make sense to make a theme dependant constant like:
I'm not sure about this and we need to reach a concensus about this before I am going to start coding on this, which is pretty straight forward.
Comment #2
Stefan Nagtegaal CreditAttribution: Stefan Nagtegaal commentedi think this should be the right status for this...
Comment #3
drewish CreditAttribution: drewish commentedI disagree, I think it's a preset dependent setting. Some of my presets I want to have a white background, others gray and others transparent. I shouldn't have to pick one for the entire site.
Comment #4
drewish CreditAttribution: drewish commentedAfter spending a little time working on a patch for this I'm understanding what you're saying. But I think we actually need to take a slightly different tactic and specify color and transparency separately, e.g.
becomes:
and
becomes:
This way the background color can be specified without needing to be concerned about the file format. If it supports transparency then you get transparent backgrounds and if not you get the specified color. Update: or in the case of GIF files, you can specify which color will be used for transparency if one isn't already in use.
Comment #5
dergachev CreditAttribution: dergachev commentedI spent some time trying to figure this out but imagecopyresampled was just too much of a beast.
Fortunately, the fantastic module Imagecache Actions provides a few additional actions that do what I need here.
Specifically, the "Define Canvas" action is just a negative crop with a color picker.
See http://drupal.org/project/imagecache_actions
Perhaps at least some of those actions should follow Imagecache into core?
Comment #6
drewish CreditAttribution: drewish commentedMan this code is really tricky to get right. Here's my broken but in progress patch that at least works for rotation. Cropping still needs a ton of work.
The code is borked enough that the unit tests aren't helpful since you can't see what's wrong. So I've been using this snip it in the PHP execute block to test it:
Comment #7
hanoiiVery interested in this issue as I am experiencing the black background behavior in D5 with version 1.5, not with 1.4.
Comment #8
dman CreditAttribution: dman commentedAny reason why you are not using imageapi_hex2rgba() ?
This triggered me to write up my suggestion for improvements to color passing over at : #471816: API suggestion - use keyed color names, not ints in imageapi_hex2rgba()
Comment #9
drewish CreditAttribution: drewish commentedwell imageapi_hex2rgba() isn't in core and i benchmarked it and the for loop is actually slower than just doing it in an array.
Comment #10
drewish CreditAttribution: drewish commentedComment #11
jantoine CreditAttribution: jantoine commentedsubscribe