TikZ: complex mask over image (even odd rule)

Clash Royale CLAN TAG#URR8PPP
up vote
4
down vote
favorite
I need to draw masks (with various shapes) over an image. For example, I made a circle mask like this:
documentclass[border=10pt]standalone
usepackagetikz
definecolorbackgroundHTML2C414C
definecolorforegroundHTMLFFFFFF
usetikzlibrarypositioning,fit
begindocument
begintikzpicture[inner sep=0pt, outer sep=0pt, draw=foreground, fill=foreground]
node (image) includegraphicsexample-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
endtikzpicture
enddocument

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:
begintikzpicture[inner sep=0pt, outer sep=0pt, draw=foreground, fill=foreground]
node (image) includegraphicsexample-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;
endtikzpicture
Error: ! Use of @next doesn't match its definition.
tikz-pgf diagrams
add a comment |Â
up vote
4
down vote
favorite
I need to draw masks (with various shapes) over an image. For example, I made a circle mask like this:
documentclass[border=10pt]standalone
usepackagetikz
definecolorbackgroundHTML2C414C
definecolorforegroundHTMLFFFFFF
usetikzlibrarypositioning,fit
begindocument
begintikzpicture[inner sep=0pt, outer sep=0pt, draw=foreground, fill=foreground]
node (image) includegraphicsexample-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
endtikzpicture
enddocument

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:
begintikzpicture[inner sep=0pt, outer sep=0pt, draw=foreground, fill=foreground]
node (image) includegraphicsexample-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;
endtikzpicture
Error: ! Use of @next doesn't match its definition.
tikz-pgf diagrams
add a comment |Â
up vote
4
down vote
favorite
up vote
4
down vote
favorite
I need to draw masks (with various shapes) over an image. For example, I made a circle mask like this:
documentclass[border=10pt]standalone
usepackagetikz
definecolorbackgroundHTML2C414C
definecolorforegroundHTMLFFFFFF
usetikzlibrarypositioning,fit
begindocument
begintikzpicture[inner sep=0pt, outer sep=0pt, draw=foreground, fill=foreground]
node (image) includegraphicsexample-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
endtikzpicture
enddocument

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:
begintikzpicture[inner sep=0pt, outer sep=0pt, draw=foreground, fill=foreground]
node (image) includegraphicsexample-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;
endtikzpicture
Error: ! Use of @next doesn't match its definition.
tikz-pgf diagrams
I need to draw masks (with various shapes) over an image. For example, I made a circle mask like this:
documentclass[border=10pt]standalone
usepackagetikz
definecolorbackgroundHTML2C414C
definecolorforegroundHTMLFFFFFF
usetikzlibrarypositioning,fit
begindocument
begintikzpicture[inner sep=0pt, outer sep=0pt, draw=foreground, fill=foreground]
node (image) includegraphicsexample-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
endtikzpicture
enddocument

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:
begintikzpicture[inner sep=0pt, outer sep=0pt, draw=foreground, fill=foreground]
node (image) includegraphicsexample-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;
endtikzpicture
Error: ! Use of @next doesn't match its definition.
tikz-pgf diagrams
tikz-pgf diagrams
edited 13 hours ago
asked 13 hours ago
kontextify
1665
1665
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
5
down vote
accepted
Draw the heart with only one path:
documentclass[border=10pt]standalone
usepackagetikz
definecolorbackgroundHTML2C414C
definecolorforegroundHTMLFFFFFF
usetikzlibrarypositioning,fit
begindocument
begintikzpicture[inner sep=0pt, outer sep=0pt, draw=foreground, fill=foreground]
node (image) includegraphicsexample-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;
endtikzpicture
enddocument

And with relative coordinates in hart definition, it's easier to place wherever you want over the image:
documentclass[border=10pt]standalone
usepackagetikz
definecolorbackgroundHTML2C414C
definecolorforegroundHTMLFFFFFF
usetikzlibrarypositioning,fit
newcommandhart.. 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
begindocument
begintikzpicture[inner sep=0pt, outer sep=0pt, draw=foreground, fill=foreground]
node (image) includegraphicsexample-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;
endtikzpicture
enddocument

@kontextify: may be you are interested in updated answer
â Ignasi
5 hours ago
add a comment |Â
up vote
3
down vote
Seems, there was two times draw an one ; to much.

documentclass[border=10pt, tikz]standalone
usepackagetikz
definecolorbackgroundHTML2C414C
definecolorforegroundHTMLFFFFFF
usetikzlibrarypositioning,fit
begindocument
begintikzpicture[inner sep=0pt, outer sep=0pt, draw=foreground, fill=foreground]
node (image) includegraphicsexample-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
endtikzpicture
begintikzpicture[inner sep=0pt, outer sep=0pt, draw=foreground, fill=foreground]
node (image) includegraphicsexample-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;
endtikzpicture
enddocument
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
accepted
Draw the heart with only one path:
documentclass[border=10pt]standalone
usepackagetikz
definecolorbackgroundHTML2C414C
definecolorforegroundHTMLFFFFFF
usetikzlibrarypositioning,fit
begindocument
begintikzpicture[inner sep=0pt, outer sep=0pt, draw=foreground, fill=foreground]
node (image) includegraphicsexample-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;
endtikzpicture
enddocument

And with relative coordinates in hart definition, it's easier to place wherever you want over the image:
documentclass[border=10pt]standalone
usepackagetikz
definecolorbackgroundHTML2C414C
definecolorforegroundHTMLFFFFFF
usetikzlibrarypositioning,fit
newcommandhart.. 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
begindocument
begintikzpicture[inner sep=0pt, outer sep=0pt, draw=foreground, fill=foreground]
node (image) includegraphicsexample-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;
endtikzpicture
enddocument

@kontextify: may be you are interested in updated answer
â Ignasi
5 hours ago
add a comment |Â
up vote
5
down vote
accepted
Draw the heart with only one path:
documentclass[border=10pt]standalone
usepackagetikz
definecolorbackgroundHTML2C414C
definecolorforegroundHTMLFFFFFF
usetikzlibrarypositioning,fit
begindocument
begintikzpicture[inner sep=0pt, outer sep=0pt, draw=foreground, fill=foreground]
node (image) includegraphicsexample-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;
endtikzpicture
enddocument

And with relative coordinates in hart definition, it's easier to place wherever you want over the image:
documentclass[border=10pt]standalone
usepackagetikz
definecolorbackgroundHTML2C414C
definecolorforegroundHTMLFFFFFF
usetikzlibrarypositioning,fit
newcommandhart.. 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
begindocument
begintikzpicture[inner sep=0pt, outer sep=0pt, draw=foreground, fill=foreground]
node (image) includegraphicsexample-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;
endtikzpicture
enddocument

@kontextify: may be you are interested in updated answer
â Ignasi
5 hours ago
add a comment |Â
up vote
5
down vote
accepted
up vote
5
down vote
accepted
Draw the heart with only one path:
documentclass[border=10pt]standalone
usepackagetikz
definecolorbackgroundHTML2C414C
definecolorforegroundHTMLFFFFFF
usetikzlibrarypositioning,fit
begindocument
begintikzpicture[inner sep=0pt, outer sep=0pt, draw=foreground, fill=foreground]
node (image) includegraphicsexample-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;
endtikzpicture
enddocument

And with relative coordinates in hart definition, it's easier to place wherever you want over the image:
documentclass[border=10pt]standalone
usepackagetikz
definecolorbackgroundHTML2C414C
definecolorforegroundHTMLFFFFFF
usetikzlibrarypositioning,fit
newcommandhart.. 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
begindocument
begintikzpicture[inner sep=0pt, outer sep=0pt, draw=foreground, fill=foreground]
node (image) includegraphicsexample-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;
endtikzpicture
enddocument

Draw the heart with only one path:
documentclass[border=10pt]standalone
usepackagetikz
definecolorbackgroundHTML2C414C
definecolorforegroundHTMLFFFFFF
usetikzlibrarypositioning,fit
begindocument
begintikzpicture[inner sep=0pt, outer sep=0pt, draw=foreground, fill=foreground]
node (image) includegraphicsexample-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;
endtikzpicture
enddocument

And with relative coordinates in hart definition, it's easier to place wherever you want over the image:
documentclass[border=10pt]standalone
usepackagetikz
definecolorbackgroundHTML2C414C
definecolorforegroundHTMLFFFFFF
usetikzlibrarypositioning,fit
newcommandhart.. 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
begindocument
begintikzpicture[inner sep=0pt, outer sep=0pt, draw=foreground, fill=foreground]
node (image) includegraphicsexample-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;
endtikzpicture
enddocument

edited 5 hours ago
answered 13 hours ago
Ignasi
88k4159293
88k4159293
@kontextify: may be you are interested in updated answer
â Ignasi
5 hours ago
add a comment |Â
@kontextify: may be you are interested in updated answer
â Ignasi
5 hours ago
@kontextify: may be you are interested in updated answer
â Ignasi
5 hours ago
@kontextify: may be you are interested in updated answer
â Ignasi
5 hours ago
add a comment |Â
up vote
3
down vote
Seems, there was two times draw an one ; to much.

documentclass[border=10pt, tikz]standalone
usepackagetikz
definecolorbackgroundHTML2C414C
definecolorforegroundHTMLFFFFFF
usetikzlibrarypositioning,fit
begindocument
begintikzpicture[inner sep=0pt, outer sep=0pt, draw=foreground, fill=foreground]
node (image) includegraphicsexample-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
endtikzpicture
begintikzpicture[inner sep=0pt, outer sep=0pt, draw=foreground, fill=foreground]
node (image) includegraphicsexample-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;
endtikzpicture
enddocument
add a comment |Â
up vote
3
down vote
Seems, there was two times draw an one ; to much.

documentclass[border=10pt, tikz]standalone
usepackagetikz
definecolorbackgroundHTML2C414C
definecolorforegroundHTMLFFFFFF
usetikzlibrarypositioning,fit
begindocument
begintikzpicture[inner sep=0pt, outer sep=0pt, draw=foreground, fill=foreground]
node (image) includegraphicsexample-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
endtikzpicture
begintikzpicture[inner sep=0pt, outer sep=0pt, draw=foreground, fill=foreground]
node (image) includegraphicsexample-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;
endtikzpicture
enddocument
add a comment |Â
up vote
3
down vote
up vote
3
down vote
Seems, there was two times draw an one ; to much.

documentclass[border=10pt, tikz]standalone
usepackagetikz
definecolorbackgroundHTML2C414C
definecolorforegroundHTMLFFFFFF
usetikzlibrarypositioning,fit
begindocument
begintikzpicture[inner sep=0pt, outer sep=0pt, draw=foreground, fill=foreground]
node (image) includegraphicsexample-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
endtikzpicture
begintikzpicture[inner sep=0pt, outer sep=0pt, draw=foreground, fill=foreground]
node (image) includegraphicsexample-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;
endtikzpicture
enddocument
Seems, there was two times draw an one ; to much.

documentclass[border=10pt, tikz]standalone
usepackagetikz
definecolorbackgroundHTML2C414C
definecolorforegroundHTMLFFFFFF
usetikzlibrarypositioning,fit
begindocument
begintikzpicture[inner sep=0pt, outer sep=0pt, draw=foreground, fill=foreground]
node (image) includegraphicsexample-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
endtikzpicture
begintikzpicture[inner sep=0pt, outer sep=0pt, draw=foreground, fill=foreground]
node (image) includegraphicsexample-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;
endtikzpicture
enddocument
answered 13 hours ago
cis
442412
442412
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f454482%2ftikz-complex-mask-over-image-even-odd-rule%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password