MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Transparent background with PNG

On Feb 20, 5:47 am, replicator... at wrote:
> Hi,
> how can I save an image to PNG format (eg. a simple plot), with the
> (white) background being transparent? I understand that PNG export
> supports alpha channel, but have no clue how to instruct Mathematica
> to exploit it.

This seems to be excessively obscure, but I got a png with a
transparent background this way (in V7):

plotImage = Plot[x^2, {x, 0, 2}]

bkgImage =
 Image[ConstantArray[{0., 0., 0., 0.},
   Reverse[ImageDimensions[plotImage]]], ColorSpace -> "RGB"]

compImage = ImageCompose[bkgImage, plotImage]

Export["~/Desktop/compImage.png", compImage]

It seems that composing the graphic against a transparent image gives
it an alpha channel.

  • Prev by Date: Re: Bug in Export to HTML in v7?
  • Next by Date: Re: About Reduce and Mod
  • Previous by thread: Re: Transparent background with PNG
  • Next by thread: Re: Transparent background with PNG