0

I have a tikz picture that is basically some rectangles filled with simple commands such as

\draw[black,fill=Black](0.8,0.55)--(1.2,0.55)--(1.2,0.9)--(0.8,0.9)--cycle;

Nothing fancy.

I save them as a standalone, and then using imagemagics convert.exe I run

convert -density 900 mypdf.pdf mypng.png

for maximum quality. However, sometimes the render is not right, there are gaps between the fill and the border of the shapes, as you can see in some of the figures. Note how this also happens with circles and other shapes. Note also how only sometimes happens, and this effect is not unique to black.

How can I fix this?

Note: A specific fix for a single command/color combination does not work as I do have a wide variety of shapes and color sin different cases and lot of them show this effect. I know I can do \fill, but there are different color boundaries and color backgrounds. I understand that "redo the entire thing with better commands" may be a valid answer, but that is not the one I am asking about.

enter image description here

enter image description here

MWE:

\documentclass{standalone}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}


\begin{document}
\begin{tikzpicture}

\draw[rounded corners=0.5mm,black,fill=Gray!10](0.1,0.1)rectangle (-0.2,0.9){};
\draw[rounded corners=0.5mm,black,fill=Gray!10](1.9,0.1)rectangle (2.2,0.9){};


\draw[black,fill=Gray!30](0,0)--(2,0)--(2,1)--(0,1)--cycle;
\draw[black,fill=Black](0.8,0.1)--(1.2,0.1)--(1.2,0.45)--(0.8,0.45)--cycle;
\draw[black,fill=Black](0.8,0.55)--(1.2,0.55)--(1.2,0.9)--(0.8,0.9)--cycle;
\draw[black,fill=red,opacity=0.5](0.85,0.6)--(1.15,0.6)--(1.15,0.85)--(0.85,0.85)--cycle;

\draw[fill=white] (-0.1,0.8) circle (0.04);
\draw[fill=white] (-0.1,0.2) circle (0.04);
\draw[fill=white] (2.1,0.8) circle (0.04);
\draw[fill=white] (2.1,0.2) circle (0.04);
\draw[black,thick,fill=Gray!10](0.1,0.1)rectangle (0.6,0.9){};

\draw[black,fill=Black](1.6,0.45)rectangle (1.8,0.55){};


\draw[fill=black] (1.6,0.2) circle (0.06);
\end{tikzpicture}
\end{document}
Ander Biguri
  • 1,837

1 Answers1

2

It's possible to remove the artefacts by not using anti-aliasing in the conversion.

e.g., directly with ghostscript:

gs -dSAFER -dNOPAUSE -dBATCH -sOutputFile=mypng.png -sDEVICE=pngalpha -r900 -dTextAlphaBits=1 -dGraphicsAlphaBits=1 mypdf.pdf

To avoid the jagged edges, then you could render it at a higher resolution and then re-sample it back down.

David Purton
  • 25,884