vectorgraphics / asymptote

2D & 3D TeX-Aware Vector Graphics Language
https://asymptote.sourceforge.io/
GNU General Public License v3.0
542 stars 90 forks source link

Making the background of PNG output transparent #358

Closed yarusome closed 1 year ago

yarusome commented 1 year ago

The following code piece produces a PNG image with a transparent background using Asymptote 2.70 but with a white background using 2.83:

settings.outformat = "png";
unitsize(5cm);
draw(unitcircle);

The interesting part is that if:

  1. commenting out the first line;
  2. converting the output PDF (say output.pdf) using magick output.pdf output.png;

then output.png does have a transparent background, which confirms that the background of output.pdf is not set to be white.

Is this behavioral change intended during updates somewhere between 2.70 and 2.83? If so, how to make Asymptote produce PNG output with a transparent background now? Adding settings.convertOptions = ""; is of no avail.


ImageMagick version: 7.1.0-45 Q8 x64

johncbowman commented 1 year ago

If you want a transparent background, you need to use the pngalpha driver instead of the default png16m driver (the driver recommended by the ghostscript developers for normal use):

settings.pngdriver="pngalpha";