4

I need to draw masks (with various shapes) over an image. For example, I made a circle mask like this:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\definecolor{background}{HTML}{2C414C}
\definecolor{foreground}{HTML}{FFFFFF}
\usetikzlibrary{positioning,fit}
\begin{document}
\begin{tikzpicture}[inner sep=0pt, outer sep=0pt, draw=foreground, fill=foreground]
  \node (image) {\includegraphics{example-image}};
  \fill [red, opacity=0.5,even odd rule]
    (image.north west) rectangle (image.south east) % Cover up everything
    (0,1) circle [radius=50pt]; % Punch a hole
\end{tikzpicture}
\end{document}

mask example

How do I use a more complex shape instead of the circle? Specifically, I need a heart shape. I tried using the one from this answer, but it either causes errors or doesn't appear:

\begin{tikzpicture}[inner sep=0pt, outer sep=0pt, draw=foreground, fill=foreground]
  \node (image) {\includegraphics{example-image}};
  \fill [red, opacity=0.5,even odd rule]
    (image.north west) rectangle (image.south east)
    (0,1) draw .. controls (0,0.75) and (-1.5,1.00) .. (-1.5,2)  arc (180:0:0.75)  -- cycle;
    (0,1) draw .. controls (0,0.75) and ( 1.5,1.00) .. ( 1.5,2)  arc (0:180:0.75) -- cycle;
\end{tikzpicture}

Error: ! Use of \@next doesn't match its definition.

5

Draw the heart with only one path:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\definecolor{background}{HTML}{2C414C}
\definecolor{foreground}{HTML}{FFFFFF}
\usetikzlibrary{positioning,fit}
\begin{document}
\begin{tikzpicture}[inner sep=0pt, outer sep=0pt, draw=foreground, fill=foreground]
  \node (image) {\includegraphics{example-image}};
  \fill [red, opacity=0.5,even odd rule]
    (image.north west) rectangle (image.south east)
    (0,1) .. controls (0,1.75) and (-1.5,2.00) .. (-1.5,3)  arc (180:0:0.75)  arc (180:0:0.75)
    .. controls ( 1.5,2.00) and (0,1.75) .. (0,1) --cycle;
\end{tikzpicture}
\end{document}

enter image description here

And with relative coordinates in hart definition, it's easier to place wherever you want over the image:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\definecolor{background}{HTML}{2C414C}
\definecolor{foreground}{HTML}{FFFFFF}
\usetikzlibrary{positioning,fit}

\newcommand{\hart}{.. controls +(0,.75) and +(0,-1.00) .. ++(-1.5,2)  arc (180:0:0.75) arc (180:0:0.75)
    .. controls +(0,-1.00) and +(0,.75) .. cycle}

\begin{document}
\begin{tikzpicture}[inner sep=0pt, outer sep=0pt, draw=foreground, fill=foreground]
  \node (image) {\includegraphics{example-image}};
  \fill [red, opacity=0.5,even odd rule]
    (image.north west) rectangle (image.south east)
    {[rotate=90, scale=.5](image.center)\hart} 
    {[scale=1.5](image.center)\hart}
    {[rotate=-50]([shift={(1,2)}]image.south west)\hart};
\end{tikzpicture}
\end{document}

enter image description here

  • @kontextify: may be you are interested in updated answer – Ignasi Oct 9 '18 at 17:45
3

Seems, there was two times draw an one ; to much.

enter image description here

\documentclass[border=10pt, tikz]{standalone}
\usepackage{tikz}
\definecolor{background}{HTML}{2C414C}
\definecolor{foreground}{HTML}{FFFFFF}
\usetikzlibrary{positioning,fit}

\begin{document}

\begin{tikzpicture}[inner sep=0pt, outer sep=0pt, draw=foreground, fill=foreground]
  \node (image) {\includegraphics{example-image}};
  \fill [red, opacity=0.5,even odd rule]
    (image.north west) rectangle (image.south east) % Cover up everything
    (0,1) circle [radius=50pt]; % Punch a hole
\end{tikzpicture}

\begin{tikzpicture}[inner sep=0pt, outer sep=0pt, draw=foreground, fill=foreground]
  \node (image) {\includegraphics{example-image}};
  \fill [red, opacity=0.5,even odd rule,]
   (image.north west) rectangle (image.south east)
(0,1) .. controls (0,0.75) and (-1.5,1.00) .. (-1.5,2)  arc (180:0:0.75)  -- cycle
(0,1) .. controls (0,0.75) and ( 1.5,1.00) .. ( 1.5,2)  arc (0:180:0.75) -- cycle;
\end{tikzpicture}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.