1

The basis of the following code Cf. How can I clip an image via a bezier-path?

Consider

\documentclass{article}
    \usepackage{tikz}
    \usepackage{graphicx}
\newif\ifdeveloppath
\tikzset{/tikz/develop clipping path/.is if=developpath,
  /tikz/develop clipping path=true}

\newcommand{\clippicture}[2]{
\begin{tikzpicture}
\ifdeveloppath
  \node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics{ramanujan}};
\else
  \node[anchor=south west,inner sep=0] (image) at (0,0) {\phantom{\includegraphics{ramanujan}}};
\fi
\pgfresetboundingbox
\begin{scope}[x={(image.south east)},y={(image.north west)}]
    \ifdeveloppath
    \draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1);
    \foreach \x in {0,1,...,9} { \node [anchor=north] at (\x/10,0) {0.\x}; }
    \foreach \y in {0,1,...,9} { \node [anchor=east] at (0,\y/10) {0.\y}; }
    \draw[red, ultra thick] #2 -- cycle;
  \else
    \path[clip] #2 -- cycle;
    \node[anchor=south west,inner sep=0pt] {\includegraphics{ramanujan}};
  \fi
\end{scope}
\end{tikzpicture}
}


\begin{document} \hskip 25pt \textbf{Ramanujan} \vskip 7pt \clippicture{[width=0.8\textwidth]{some-image}}{(0.1,1.00) -- (0.80,1.00) -- (0.8,0.5) .. controls (0.8,-0.2) and (0.35,0.2) .. (0.1,0.3)}

\tikzset{develop clipping path=false}

\vskip 25pt

\clippicture{[width=0.8\textwidth]{some-image}}{(0.1,1.00) -- (0.80,1.00) -- (0.8,0.5) .. controls (0.8,-0.2) and (0.35,0.2) .. (0.1,0.3)}

\vskip 20pt

\noindent \textbf{QUESTION: How to adjust the display size of this cropped image?} \end{document}

enter image description here

QUESTION: I would like to be able to increase/decrease the visual appearance of the cropped image, but techniques that one would apply to an \includegraphics situation do not seem to work here. Does anyone know how to accomplish this here?

Thank you.

DDS
  • 8,816
  • 4
  • 9
  • 36

1 Answers1

2

You can use adjustbox to scale the clip.

a

c

\documentclass{article}
\usepackage{tikz}
\usepackage{graphicx}

\usepackage[left=2.00cm, right=2.00cm, top=1.00cm, bottom=1.00cm]{geometry}

\newif\ifdeveloppath \tikzset{/tikz/develop clipping path/.is if=developpath, /tikz/develop clipping path=true}

\newcommand{\clippicture}[2]{ \begin{tikzpicture} \ifdeveloppath \node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics{example-grid-100x100pt}}; \else \node[anchor=south west,inner sep=0] (image) at (0,0) {\phantom{\includegraphics{example-grid-100x100pt}}}; \fi \pgfresetboundingbox \begin{scope}[x={(image.south east)},y={(image.north west)}] \ifdeveloppath \draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1); \foreach \x in {0,1,...,9} { \node [anchor=north] at (\x/10,0) {0.\x}; } \foreach \y in {0,1,...,9} { \node [anchor=east] at (0,\y/10) {0.\y}; } \draw[red, ultra thick] #2 -- cycle; \else \path[clip] #2 -- cycle; \node[anchor=south west,inner sep=0pt] {\includegraphics{example-grid-100x100pt}}; \fi \end{scope} \end{tikzpicture} } \usepackage{adjustbox} % added <<<<<<<<<<

\begin{document} \hskip 25pt \textbf{example-grid-100x100pt} \vskip 7pt \clippicture{[width=0.8\textwidth]{some-image}}{(0.1,1.00) -- (0.80,1.00) -- (0.8,0.5) .. controls (0.8,-0.2) and (0.35,0.2) .. (0.1,0.3)}

\tikzset{develop clipping path=false}

\vskip 25pt

Original size\medskip

\clippicture{[width=0.8\textwidth]{some-image}}{(0.1,1.00) -- (0.80,1.00) -- (0.8,0.5) .. controls (0.8,-0.2) and (0.35,0.2) .. (0.1,0.3)}

\newpage

Reduced size \medskip

\begin{adjustbox}{width={0.1\linewidth},keepaspectratio} % change width to scale <<<<<< \tikzset{develop clipping path=false}
\clippicture{[width=0.8\textwidth]{some-image}}{(0.1,1.00) -- (0.80,1.00) -- (0.8,0.5) .. controls (0.8,-0.2) and (0.35,0.2) .. (0.1,0.3)} \end{adjustbox}

Enlarged size \medskip

\begin{adjustbox}{width={0.5\linewidth},keepaspectratio} % change width to scale <<<<<< \tikzset{develop clipping path=false}
\clippicture{[width=0.8\textwidth]{some-image}}{(0.1,1.00) -- (0.80,1.00) -- (0.8,0.5) .. controls (0.8,-0.2) and (0.35,0.2) .. (0.1,0.3)} \end{adjustbox}

\end{document}

Simon Dispa
  • 39,141