14

Is it possible to change the black background colour to another colour (e.g. white) when cropping an image that is smaller than the crop size?

I'm using the "image styles" settings in Drupal 7 to first scale the image to the correct width and then cropping to get the desired height. This results in some of the images having black borders that really don't look nice (and the client doesn't like).

Any other suggestions to fixing this would be appreciated.

23

You could try with ImageCache Actions module. Enable Imagecache Canvas Actions module that is shipped with ImageCache Actions and than change your style effects order to:

  1. Scale
  2. Define canvas (set your color and scale dimensions)
  3. Crop
  • The name changed to "Image Effects module" in Drupal 8 (see other answers) – dude Jun 21 '18 at 13:07
3

For Drupal 8 you'll use the Image Effects module. This will provide additional options for your Drupal "image styles". The most effective way I have found to do this is to create an image style with the following effects:

  • Scale either a width or height.
  • Set canvas - Exact size. Give it the width and height of the final image style and provide a background image. It defaults to transparent so uncheck that and provide your own colour.
  • Crop to size (the width and height you applied to the canvas above).

Image atached of an example with a red canvas enter image description here

1

These two modules can meet your requirement.

Image effect kit module.

Image effect kit provides some image effects to be used on an image styles. It includes the following effects:

  • Border effect
  • Rounded corner effect
  • Padding effect
  • Watermark effect
  • Resizing effect
  • Overlay effect
  • Filter effect

image effect module.

Resize an image to an exact set of dimensions size without any crop, stretch, or shrunk, but will add white background if need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.