如何缩放裁剪图像的显示尺寸

如何缩放裁剪图像的显示尺寸

以下代码的基础参见如何通过贝塞尔路径剪辑图像?

考虑

\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}

在此处输入图片描述

问题:我希望能够增加/减少裁剪图像的视觉效果,但在某些\includegraphics情况下应用的技术似乎在这里不起作用。有人知道如何在这里实现这一点吗?

谢谢。

答案1

您可以使用adjustbox它来缩放剪辑。

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}

相关内容