# Convert to png (imagemagic) introduces errors with basic figures

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.

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}

• Can you try \fill[Black](0.8,0.55)--(1.2,0.55)--(1.2,0.9)--(0.8,0.9)--cycle;? – samcarter is at topanswers.xyz Aug 7 '18 at 11:42
• @samcarter well, yeah, but it doesn't only happen with black. I still want a border in the ones that are not black. – Ander Biguri Aug 7 '18 at 11:43
• You could replace the non-black rectangles with two rectangles. A black bigger one below and a smaller red one above. – samcarter is at topanswers.xyz Aug 7 '18 at 11:44
• @samcarter as you can see with the new image, it happens in general. Is the only option just duplicating everything so that there is a command for fill and a command for the border? – Ander Biguri Aug 7 '18 at 11:47
• Maybe tex.stackexchange.com/a/328293/36296 could help (I did not test) – samcarter is at topanswers.xyz Aug 7 '18 at 11:47

e.g., directly with ghostscript:
gs -dSAFER -dNOPAUSE -dBATCH -sOutputFile=mypng.png -sDEVICE=pngalpha -r900 -dTextAlphaBits=1 -dGraphicsAlphaBits=1 mypdf.pdf

• For completeness, in imagemagic convert the option is +antialias. – Ander Biguri Aug 7 '18 at 14:08