I’m dealing with a lot of images with a transparent background on a Kirby site, and was wondering if there was a way of generating versions of them with an added background colour, based on the value of a field on the page (in the same way that there’s a lot of options like crop and focal point)?
Something like:
$image->illustration()->addBackground('background-color')->toFile()
If not a built-in functionality (not expecting it to be!) has anyone has already solved this with a plugin? Or even with a standard colour (not based on a field value)? Ideally with webp, but PNG would work too.
No, there is no built-in way to add a background to the image itself. I think the most simple way would be to add a background color to the container that holds the image?
I’m thinking for contexts like the RSS feed or social sharing images. I need the images to be transparent and use the page’s background colour on the site, but other for instances that colour needs to be part of the image. I guess one way is to create a JPG, which always make it white.
Another option would be to create a custom thumbs driver. Not sure from the top of my head if the standard gd library supports adding background c9lors, but should work with imagemagick. This would require some coding skills, though.
That’s what I thought, thanks Sonja!