3

I can successfully create PDF figures using TikZ and convert them with convert (ImageMagick) to PNG such that retain a transparent background. However, with the same procedure, for some of my figures, I instead get a white background. It seems that this happens whenever I have semi-transparent elements in the figure (see another SE-question, where this conclusion is implicit in the answer). This is on Mac OS X. If I use Inkscape, I can get a semi-transparent background, but it typically messes up the fonts (and I don't know how to do it via the CLI).

MWE:

\RequirePackage{luatex85}
\documentclass{standalone}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\draw[blue,fill=green,fill opacity=0.1] (0,0) circle (1);
\end{tikzpicture}
\end{document}

The \RequirePackage{luatex85} is there because I use a very recent LuaTeX that causes problems with some packages. Convert with convert -background transparent test.pdf test.png. The result is:

Result after conversion

If fill opacity=0.1 is removed, the result looks as follows:

Result after conversion, with fill opacity removed

burnpanck
  • 339
  • As usual, we can do nothing without a MWE to test things on. – John Kormylo Feb 12 '17 at 20:49
  • You are right of course, here it is. – burnpanck Feb 12 '17 at 21:40
  • Here, with convert version 6.8.9-9, I get the correct result. – Paul Gaborit Feb 12 '17 at 21:59
  • 1
    Interesting! My convert is version 6.9.7-1. Is it a MacOSX specific thing? Or is lualatexthe problem (mine is 0.95.0, TeX Live 2016) ? – burnpanck Feb 12 '17 at 22:23
  • I ran it with pdflatex and lualatex (minus the luatex85, which crashed) and converted with Adobe Acrobat and GIMP with no problems. Gimp offered removing hidden or transparent layers as an option. – John Kormylo Feb 13 '17 at 02:56
  • The conversion to png should not be necessary... – Martin Schröder Feb 13 '17 at 20:49
  • @MartinSchröder: Well, there are use-cases, where such a conversion IS necessary. In my case, it is for a web-based presentation, where strictly speaking, SVG would offer better quality (vector), but performance suffers when there is too much of it. – burnpanck Feb 13 '17 at 21:55
  • @burnpanck convert calls gs to convert a PDF file to PNG. Here, gs --version gives 9.19 (I use the same lualatex version that yours). – Paul Gaborit Feb 13 '17 at 22:43
  • @PaulGaborit That is it! Mine was version 9.10, now with 9.20 it is fixed. If you care to write a full answer, I'd accept it. – burnpanck Feb 14 '17 at 19:37

1 Answers1

1

convert calls gs (ghostscript) to convert a PDF file to PNG. gs version 9.10 seems produce a white background if the PDF file contains semi-transparent objects. A recent version of gs (as 9.19 or 9.20) produces the correct result.

enter image description here

Paul Gaborit
  • 70,770
  • 10
  • 176
  • 283