joomla/joomla-cms — pull request #1562 by piotr-cz (2013-07-18 15:02:44+00:00)
Title: New feature: JImageFilterBackgroundfill

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.

## Usage
```PHP
// Load up image
$img = new JImage(JPATH_SITE . '/images/powered_by.png');

// Set background color using JImageFilterBackground
$img->filter('backgroundfill', array('color' => '#ff0000'));

// Save image to file
$img->toFile(JPATH_SITE . '/images/powered_by_bg.jpg', IMAGETYPE_JPEG, array('quality' => 75));
```

Alternatively color may be defined as an array.
If a color value is omitted, it defaults to 0.
```PHP
$img->filter('backgroundfill', array('color' => array('red' => 255, 'green' => 0, 'blue' => 0));
```

It's possible to use semi-transparent color too ('ff' or 127 means full opacity):
`array('color' => '#ff000080')` equals to `array('color' => array('red' => 255, 'alpha' => 64));`