latextikztexnic-center

Is it possible to extract TikZ diagrams as image files?


I’m using TikZ to draw diagrams in LaTeX that I then want to isolate as image files to put online. I’m using TeXnicCenter to edit the sources.

Is there is a way to extract these diagrams directly without having to extract them from the finished PDF file?


Solution

  • Following up on my comment: Cirkuit converts TikZ diagrams into images by running something like the following sequence of commands:

    pdflatex img.tex
    pdftops -eps img.pdf
    convert -density 300 img.eps img.png
    

    Here img.tex would be a LaTeX file that follows this template:

    \documentclass{article}
    \usepackage{tikz,amsmath,siunitx}
    \usetikzlibrary{arrows,snakes,backgrounds,patterns,matrix,shapes,fit,calc,shadows,plotmarks}
    \usepackage[graphics,tightpage,active]{preview}
    \PreviewEnvironment{tikzpicture}
    \PreviewEnvironment{equation}
    \PreviewEnvironment{equation*}
    \newlength{\imagewidth}
    \newlength{\imagescale}
    \pagestyle{empty}
    \thispagestyle{empty}
    \begin{document}
    \begin{tikzpicture}
        % (your TikZ code goes here)
    \end{tikzpicture}
    \end{document}
    

    If you are able to use Cirkuit or a similar editor, or write a script for yourself to put your diagram into that template and run the appropriate tools, you'll have a quick way to convert TikZ code into a PNG image.

    To answer your question more directly... no, I don't know of any way to convert a TikZ diagram directly to PNG without going through a PDF file (or at least DVI) at some stage.