add tag
samcarter
*Background: my git client allows to choose an icon for each repository, which makes it easier to recognise them in an overview. To do this one simply places a graphic with the name "icon" or "logo" in folder of the repository. Allowed file formats are `.tiff`, `.png`, `.jpg`, `.gif`, or `icns`. I thought it would be nice to have document automatically create such a file with the theme colour of the document.*

---

In addition to creating a document, I would also like to also create a separate pixel graphic which is a simple square filled with a solid colour. The colour is defined in the preamble of the document. How can I do this?

A simple MWE as starting point:

```
\documentclass{standalone}
\usepackage{xcolor}
\definecolor{duck}{RGB}{255, 216, 1}

\begin{document}

unrelated document content

\end{document}
```
Top Answer
samcarter
Using the colour conversion/extraction from https://tex.stackexchange.com/q/436012/36296 one can then for example pass the extracted colour to image magick to create a pixel graphic:


```
% !TeX program = txs:///arara
% arara: pdflatex: {synctex: on, interaction: nonstopmode, shell: yes}

\documentclass{article}

\usepackage{iexec}
\usepackage{xcolor}
\colorlet{duck}{yellow!50!orange}

\extractcolorspecs{duck}{\tmpmodel}{\tmpcolorspec}
\convertcolorspec{\tmpmodel}{\tmpcolorspec}{RGB}{\RGBcolorspec}
\iexec{magick -size 100x100 xc:rgb\\(\RGBcolorspec\\) icon.png}

\begin{document}
test
\end{document}
```
Answer #2
samcarter
It is probably silly to use TikZ to create a simple square, but one can use the `external` library for this:

```
% !TeX program = txs:///arara
% arara: pdflatex: {synctex: on, interaction: nonstopmode, shell: yes}
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize
\definecolor{duck}{RGB}{255, 216, 1}

\tikzset{
  png export/.style={
    external/system call/.append={
      ; convert -density 255 -transparent white "\image.pdf" "icon.png"
    }
  }
}


\newsavebox{\quack}
\AtBeginDocument{%
  \savebox{\quack}{%
    \tikzset{png export}
    \begin{tikzpicture}
    \fill[duck] (0,0) rectangle (1,1);
    \end{tikzpicture}
  }%
  \tikzexternaldisable
}

\begin{document}

text

\end{document}
```

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.