I have large figures (PNG images) in my document that are very thin but block an entire page due to their length. Is there a package available that cuts those in half, and positions those halves next to each other as one figure?
Asked
Active
Viewed 412 times
4 Answers
8
This can be quite easily done using Martin Scharrer's excellent adjustbox package:

\documentclass{article}
\usepackage{adjustbox}
\newcommand{\splitimage}[1]{%
\adjustimage{trim=0 0.5\height{} 0 0, clip=true}{#1}%
\adjustimage{trim=0 0 0 0.5\height{}, clip=true}{#1}%
}
\begin{document}
\splitimage{bottle}
\end{document}
Or using just the graphicx functionality:
\documentclass{article}
\usepackage{graphicx}
\newcommand{\splitimage}[1]{%
\newlength{\imageheight}%
\settoheight{\imageheight}{\includegraphics{#1}}%
\includegraphics[trim=0 0.5\imageheight{} 0 0, clip=true]{#1}%
\includegraphics[trim=0 0 0 0.5\imageheight{}, clip=true]{#1}%
}
\begin{document}
\splitimage{bottle}
\end{document}
Image taken from Wikimedia Comons: https://commons.wikimedia.org/wiki/File:Normflasche-1.jpg
Jake
- 232,450
3
you can clip anything of the image:
\documentclass{article}
\usepackage{graphicx,multido}
\newlength\Iwidth\newlength\Iheight\newsavebox\IBox
\savebox\IBox{\includegraphics{Normflasche}}
\setlength\Iwidth{\wd\IBox} \setlength\Iheight{\ht\IBox}
\begin{document}
\noindent
\multido{\ry=0.5+-0.5, \rY=1.0+-0.5}{2}{%
\multido{\rx=0.00+0.25, \rX=0.25+0.25}{4}{%
\fbox{\includegraphics[%
viewport={\rx\Iwidth} {\ry\Iheight} {\rX\Iwidth} \rY\Iheight,clip,scale=0.5]{Normflasche}}} \\[2pt]%
}
\end{document}

2
In ConTeXt you can use the \clip command. With \setupclipping you can select what to clip. Here I selected to clip into five slices on the vertical axis. With the x=… and y=… setting you specify which slice you want to retrieve.
\setupclipping
[nx=1, ny=5]
\starttext
\dorecurse{5}{
\clip[y=\recurselevel]{\externalfigure[hacker]}\blank}
\stoptext
result:

Marco
- 26,055
2

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{multido}
\usepackage{graphicx}
\def\Columns{5}% columns
\def\Rows{5}% rows
\def\Filename{ParisHilton}
\def\Scale{1}
\newsavebox\IBox
\savebox\IBox{\includegraphics[scale=\Scale]{\Filename}}
\psset
{
xunit=\dimexpr\wd\IBox/\Columns\relax,
yunit=\dimexpr\ht\IBox/\Rows\relax,
}
\SpecialCoor
\begin{document}
\multido{\ny=\Rows+-1}{\Rows}
{
\multido{\nx=0+1}{\Columns}
{
\pspicture(\Columns,\Rows)
\psclip{\psframe[linestyle=none,linewidth=0pt](!\nx\space \ny\space 1 sub)(!\nx\space 1 add \ny)}
\rput[bl](0,0){\usebox\IBox}
\endpsclip
\endpspicture
}
}
\end{document}
Here is the picture that I used in this answer as a demo picture.
kiss my armpit
- 36,086
imagemagick, you could batch the process and obtain the desired figures and insert them. – Dror Sep 06 '12 at 08:11