Make the background fill color configurable where image styles result in blank space

Created on 28 December 2007, over 17 years ago
Updated 25 July 2025, 12 days ago

Problem/Motivation

If you have a 'crop' image style and the image is not large enough to fill the cropped area, the resulting image has a black background in the empty space. It would be useful if the default background colour were configurable.

Note that the Image Effects module provides this functionality.

Proposed resolution

Adding a background color to the options for the 'Crop' effect when creating an image style.

Remaining tasks

N/A

User interface changes

When configuring a Crop (image_crop) effect at admin/config/media/image-styles/manage/{image_style}/add/image_rotate or admin/config/media/image-styles/manage/{image_style}/effects/{image_effect} admins should be able to provide a color, in hex string format, for the additional area created by upscaling crops.

API changes

Note: These API changes assure full backward compatibility.

Original report by FiReaNG3L

ImageAPI.module sounds very interesting; I recently had problems with imagecache / image.inc putting a black background on images when scaling / cropping to a definite size (say 150x150 pixels) when the image is too wide or tall to fit the square.

Is there a way to customize the background to another color (say, white) with image API?

I tried to modify image.inc myself but the best I could achieve is a background change that worked, but bleeded in the image if black was present.

Thanks for all the awesome work on imagecache / imageAPI!

Feature request
Status

Needs work

Version

11.0 🔥

Component

image system

Created by

Live updates comments and jobs are added and updated live.
  • Needs manual testing

    The change/bugfix cannot be fully demonstrated by automated testing, and thus requires manual testing in a variety of environments.

  • Needs backport to D7

    After being applied to the 8.x branch, it should be considered for backport to the 7.x branch. Note: This tag should generally remain even after the backport has been written, approved, and committed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024