Problem/Motivation
The background is drawn onto a canvas from imagecreatetruecolor(), which is black. A fully transparent source pixel paints nothing over it, so a logo on a transparent background comes out on black.
The dominant colour background type fails differently: it samples only the opaque pixels, so the background becomes the artwork's own colour. A single-colour logo disappears into it.
Steps to reproduce
- Add the Scale and fill background effect to an image style, background type
scaled, background styleblurred. - Run a PNG logo with a transparent background through it.
- The area around the logo is black.
With background type dominant color and a logo drawn in one colour, the derivative is a flat rectangle of that colour instead.
Proposed resolution
One setting on the effect, since an image style applies across a whole field and nothing can be decided per image.
Images with a transparent background: do nothing (the 1.0.0 behaviour); fill with a light or dark colour to suit the image; fill with a fixed colour; or fill with a tint of the image's own colour. Two colour fields back the automatic option, defaulting to white and black, so a site can match its own page colour.
These images get a plain filled background and the configured background type is not used for them, because a tiled or blurred copy of a logo is only a smeared copy of the logo. Images without a transparent background are unaffected.
API changes
None.
Data model changes
Four constrained keys are added to image.effect.scale_and_fill_background. A post update writes them into existing image styles with the handling set to none, so no existing style changes what it produces; the new default applies to effects added afterwards.
Issue fork image_scale_fill-3618813
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
vimaljoseph commented