Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.
  1. Is there a way to achieve this kind of clipping for raster images as well, not only for tikz pictures? -- Solved, see Edit #1.
  2. Are there any easier solution to achieve this with TikZ? -- Solved, see Edit #1.
  3. How to smooth the random step line a little more?

Zigzag clipping

Here is my minimal working example:

\documentclass{article}

\usepackage{tikz}
\usepgflibrary{decorations.pathmorphing}
\usetikzlibrary{decorations.pathmorphing}

\begin{document}

\begin{tikzpicture}
    \fill[black](0, 0) rectangle (72pt, 72pt);
\end{tikzpicture}
\hspace{72pt}
\begin{tikzpicture}
    \clip (0, 0) rectangle (72pt, 36pt);
    \fill[black](0, 0) rectangle (72pt, 72pt);
    \filldraw[white] (0pt, 0pt) -- (72pt, 0pt) -- (72pt, 7pt)
    decorate [decoration={random steps,segment length=2pt,amplitude=1pt}] {-- (0pt, 7pt)}
    -- cycle;
\end{tikzpicture}

\end{document}

Edit #1: Found a better solution myself. I've merged the clip and filldraw commands, so clipping with a zigzag like random line at the bottom became a little easier. MWE

Working code:

\begin{tikzpicture}
    \draw[clip] (0, 36pt)
    -- (0, 7pt)
    decorate [decoration={random steps,segment length=2pt,amplitude=1pt}] {-- (72pt, 7pt)}
    -- (72pt, 36pt)
    --cycle;
    \fill[black](0, 0) rectangle (72pt, 72pt);
\end{tikzpicture}

Clippnig a 72pt * 72pt png image (or any raster images):

\begin{tikzpicture}
    \draw[clip] (0, 36pt)
    -- (0, 7pt)
    decorate [decoration={random steps,segment length=2pt,amplitude=1pt}] {-- (72pt, 7pt)}
    -- (72pt, 36pt)
    --cycle;
    \node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[width=72pt]{black.png}};
\end{tikzpicture}

Still, there remain two unanswered questions. Let me rephrase my original third quiestion:

  • How to round the edges of the random step line?

Clipping a picture in an easy way raises another question:

  • Is there any way to set up a coordinate system at the beginning of the tikzpicture, so one shouldn't have to use exact lengths while clipping but scales instead?
share|improve this question
2  
Can't you just overlay a TikZ picture on top of a rasterized picture and use the exact same mechanism? To smooth the line more you can increase the segment length, decrease the amplitude or both. –  Roelof Spijker Nov 4 '11 at 14:04
    
For smooth edges, try the smooth keyword (manual page 229) –  Tom Bombadil Nov 5 '11 at 0:53
add comment

1 Answer

up vote 2 down vote accepted

First part of my question is answered already in the question itself, see Edit #1.

For rounding corners and using a [0,1] interval when addressing lengths during clipping I came up with this solution:

\begin{tikzpicture}[x=72pt,y=36pt]
    \draw[clip] (0, 1)
    -- (0, 0.2)
    decorate [decoration={random steps,segment length=4pt,amplitude=2pt},
              rounded corners=1pt] {-- (1, 0.1)}
    -- (1, 1)
    --cycle;
    \node[anchor=south west,inner sep=0] (image) at (0,0)
        {\includegraphics[width=72pt]{black.png}};
\end{tikzpicture}

First I added the rounded corners option to the decorated path. Second I specified the exact size of the tikzpicture at the start: \begin{tikzpicture}[x=72pt,y=36pt]. This may not be the most elegant solution but works like a charm, see the picture below (the blue box illustrates the size of the original picture).

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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