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

  1. Add the Scale and fill background effect to an image style, background type scaled, background style blurred.
  2. Run a PNG logo with a transparent background through it.
  3. 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.

Command icon 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

vimaljoseph created an issue. See original summary.

  • vimaljoseph committed cadb6966 on 1.0.x
    Issue #3618813: Fill the background for sources with transparency
    
vimaljoseph’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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