Is there an easy way to get transparent plots that work with Save Graphic As using a compatible file format such as GIF or PNG? I tried Background->Opacity[0,White] and Background->None, yet the exported PNGs appear to still have a white background.
Asked
Active
Viewed 1.4k times
41
Emre
- 1,720
- 2
- 13
- 21
-
3If questions could receive bounties, I would give you 500 right now. I couldn't find the answer to this for my life! Isn't it ironic I posted it myself 4 years ago? – Szabolcs Feb 23 '16 at 09:44
1 Answers
43
Instead of using Save Image As... you can use the Export command, like this:
Export["transparent.png", Graphics[Circle[]], Background -> None]
For this to work it is important that Background -> None is also set inside Graphics. This is the default though so unless you changed it, it should be fine.
Similarly, to convert to an image with alpha channels, use
Rasterize[Graphics[Circle[]], "Image", Background -> None]
The output of this can be saved even using Save Image As..., but this effort needed is the same because of the Rasterize function.
Szabolcs
- 234,956
- 30
- 623
- 1,263
-
-
2@Emre No, it simply doesn't provide a way to change as many options as
Exportdoes. The background is white by default when exporting. You need to change it to transparent, and this is possible withExportbut not with the simplerSave Graphic/Image As.... People typically need the white background (imagine someone putting a figure with black lines on a black-background webpage), so this is the default. – Szabolcs May 09 '12 at 08:43