User tests: Successful: Unsuccessful:
New image filter that allows filling background of image with selected color.
Obviously only applies to transparent images (like GIFs and PNGs) with 8bit as well as on 24bit color depth.
At the moment when saving images with transparency as JPEG, background color defaults to black.
I found this functionality useful when converting PNGs to JPEGs.
Issue tracker: #31520
// Load up image
$img = new JImage(JPATH_SITE . '/images/joomla_green.gif');
// Set background color using JImageFilterBackground
$img->filter('backgroundfill', array('color' => '#ff0000'));
// Save new image to file
$img->toFile(JPATH_SITE . '/images/joomla_green_bg.jpg', IMAGETYPE_JPEG, array('quality' => 85));
Alternatively color may be defined as an array.
If a color value is omitted, it defaults to 0.
$img->filter('backgroundfill', array('color' => array('red' => 255, 'green' => 0, 'blue' => 0));
It's possible to use semi-transparent color too ('ff' or 0 means full opacity):
array('color' => '#ff000080')
equals to array('color' => array('red' => 255, 'alpha' => 64));
PHP defines alpha in 7-bit range (0..128), see php.net/imagecolorallocatealpha
RGBA hexadecimal uses 8-bit values (FF..00), see wikipedia:RGBA
Resynced, updated the test.
Reference to merged Pull Request in Framework: Feature: ImageFilterBackgroundfill
Updated to current staging
branch.
Updated to staging
branch.
If anybody would like to use this filter before it's being merged in an extension, just copy it's contents to subfolder filter/backgroundfilll.php
and register it:
JLoader::register('JImageFilterBackgroundfill', __DIR__ . '/filter/backgroundfill.php');
then use like in manual at the top of this PR.
Looks like the merging in of staging has gone really wrong at some point?
Agreed. PR looks messy. It contains a lot of unrelated changes. Removed RTC for now.
If tests will pass on new superseding PR, I'll close this one.
Note to myself: I'll have to move test to new location