? Success

User tests: Successful: Unsuccessful:

avatar piotr-cz
piotr-cz
18 Jul 2013

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

Usage

// 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));

joomla_green
joomla_green_bg

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));

Side note

PHP defines alpha in 7-bit range (0..128), see php.net/imagecolorallocatealpha
RGBA hexadecimal uses 8-bit values (FF..00), see wikipedia:RGBA

avatar piotr-cz piotr-cz - open - 18 Jul 2013
avatar piotr-cz
piotr-cz - comment - 24 Sep 2013

Note to myself: I'll have to move test to new location

avatar piotr-cz
piotr-cz - comment - 3 Oct 2013

Resynced, updated the test.
Reference to merged Pull Request in Framework: Feature: ImageFilterBackgroundfill

avatar piotr-cz
piotr-cz - comment - 22 Feb 2014

Updated to current staging branch.

avatar piotr-cz
piotr-cz - comment - 12 May 2014

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.

avatar wilsonge
wilsonge - comment - 26 Aug 2014

Looks like the merging in of staging has gone really wrong at some point?

avatar Bakual
Bakual - comment - 27 Aug 2014

Agreed. PR looks messy. It contains a lot of unrelated changes. Removed RTC for now.

avatar Bakual
Bakual - comment - 27 Aug 2014

@piotr-cz Can you check what happend?

avatar piotr-cz
piotr-cz - comment - 27 Aug 2014

@Bakual, @wilsonge I've been updating this PR to latest staging branch for over a year, that's what happened.

Maybe I should create new pull request from latest staging branch?

avatar Bakual
Bakual - comment - 27 Aug 2014

@piotr-cz You can force push the correct commits to the branch, overwriting the existing one. Or you can create a new PR. Do what is easier for you.

avatar piotr-cz
piotr-cz - comment - 28 Aug 2014

If tests will pass on new superseding PR, I'll close this one.

avatar brianteeman
brianteeman - comment - 28 Aug 2014

Closing in favour of the new pull request #4189

avatar brianteeman brianteeman - close - 28 Aug 2014

Add a Comment

Login with GitHub to post a comment