lovell/sharp — pull request #91 by gasi (2014-09-23 01:12:29+00:00)
Title: Add `flatten` API for transparent images

### Background

We at @FiftyThree added this in order to flatten transparent PNGs (from [Paper](https://www.fiftythree.com/paper) app) onto a custom background color for our new product, [Mix](https://mix.fiftythree.com/):

- Original (Transparent PNG): https://d3ayzibdlq49a1.cloudfront.net/3d1d464f-fa91-4bf4-8850-45d586411cb2/image/3d1d464f-fa91-4bf4-8850-45d586411cb2_image_2048x1536.png
- Flattened JPEG: https://d3ayzibdlq49a1.cloudfront.net/3d1d464f-fa91-4bf4-8850-45d586411cb2/image/3d1d464f-fa91-4bf4-8850-45d586411cb2_image_2048x1536.jpg
- Flattened & resized JPEG: https://d3ayzibdlq49a1.cloudfront.net/3d1d464f-fa91-4bf4-8850-45d586411cb2/image/3d1d464f-fa91-4bf4-8850-45d586411cb2_image_256x192.jpg

Please consider this pull request as a starting point to discuss functionality and API. Happy to collaborate with you to make it as good as possible.

### API

#### flatten(background) or flatten(r, g, b)

Flatten transparent images onto `background` color before processing. Defaults background color to black. Pass any valid CSS color as `background`, e.g. `#00ff00`, `hsl(120,100%,50%)`, etc., or numbers in the range of `[0, 255]` for `r`, `g`, and `b`.

### Acknowledgements

@lovell, thank you for creating `sharp`. It has significantly sped up our [Mix](https://mix.fiftythree.com/) image conversion pipeline and hence improved the experience for our users. If you have an iPad and would like to try Mix, let me know and I’ll add you to the invite list.

Hat tip to @julianwa for adding the 4-bands bugfix and @apitaru for finding black fringing bug and helping fixing it :smile:

I’m planning to responding to your survey with more details soon: https://twitter.com/lovell/status/512151120496820224