\documentclass{article}
\usepackage{graphicx}
\usepackage{calc}
\usepackage{ifthen}
\newlength{\oH}
\newlength{\oW}
\newlength{\rH}
\newlength{\cH}
\newcommand\PrintImage[3]{% width, height, image
\settototalheight{\oH}{\includegraphics{#3}}%
\settowidth{\oW}{\includegraphics{#3}}%
\setlength{\rH}{\oH * \ratio{#1}{\oW}}
\ifthenelse{\lengthtest{\rH < #2}}{
\includegraphics[width=#1]{#3}%
}{%
\setlength{\cH}{(\rH-#2)*\ratio{\oW}{#1}}%
\includegraphics[width=#1,clip,trim=0 \cH{} 0 0]{#3}%
}%
}
\begin{document}
\PrintImage{6cm}{2cm}{yourimage}
\end{document}
Mit diesem Code können Sie ein 2x2 Zoll großes Passfoto erstellen. Wenn Sie A4-Papier verwenden, wie können wir das Foto in Spalten anordnen, damit mehrere Passfotos auf einer Seite erstellt werden können und kein Fotopapier verschwendet wird? Nur aus Neugier und Spaß.
Antwort1
Wie wäre es mit einer tabellarischen Anordnung environment
, wobei sich die genaue Reihenfolge nach der Größe des Fotopapiers richtet?
\documentclass{article}
\usepackage[a4paper,lmargin=0.5cm,rmargin=0.5cm,tmargin=0.2cm,bmargin=0.2cm]{geometry}
\usepackage[demo]{graphicx}
\usepackage{calc}
\usepackage{ifthen}
\newlength{\oH}
\newlength{\oW}
\newlength{\rH}
\newlength{\cH}
\newcommand\PrintImage[3]{% width, height, image
\settototalheight{\oH}{\includegraphics{#3}}%
\settowidth{\oW}{\includegraphics{#3}}%
\setlength{\rH}{\oH * \ratio{#1}{\oW}}
\ifthenelse{\lengthtest{\rH < #2}}{
\includegraphics[width=#1]{#3}%
}{%
\setlength{\cH}{(\rH-#2)*\ratio{\oW}{#1}}%
\includegraphics[width=#1,clip,trim=0 \cH{} 0 0]{#3}%
}%
}
\newlength{\extraspaceforcutting}
\setlength{\extraspaceforcutting}{0.2ex}
\begin{document}
\begin{tabular}{*{3}{@{}c@{}}}
\PrintImage{6cm}{2cm}{yourimage} &\PrintImage{6cm}{2cm}{yourimage} & \PrintImage{6cm}{2cm}{yourimage} \tabularnewline[\extraspaceforcutting]
\PrintImage{6cm}{2cm}{yourimage} &\PrintImage{6cm}{2cm}{yourimage} & \PrintImage{6cm}{2cm}{yourimage} \tabularnewline[\extraspaceforcutting]
\PrintImage{6cm}{2cm}{yourimage} &\PrintImage{6cm}{2cm}{yourimage} & \PrintImage{6cm}{2cm}{yourimage} \tabularnewline[\extraspaceforcutting]
\PrintImage{6cm}{2cm}{yourimage} &\PrintImage{6cm}{2cm}{yourimage} & \PrintImage{6cm}{2cm}{yourimage} \tabularnewline[\extraspaceforcutting]
\PrintImage{6cm}{2cm}{yourimage} &\PrintImage{6cm}{2cm}{yourimage} & \PrintImage{6cm}{2cm}{yourimage} \tabularnewline[\extraspaceforcutting]
\PrintImage{6cm}{2cm}{yourimage} &\PrintImage{6cm}{2cm}{yourimage} & \PrintImage{6cm}{2cm}{yourimage} \tabularnewline[\extraspaceforcutting]
\PrintImage{6cm}{2cm}{yourimage} &\PrintImage{6cm}{2cm}{yourimage} & \PrintImage{6cm}{2cm}{yourimage} \tabularnewline[\extraspaceforcutting]
\PrintImage{6cm}{2cm}{yourimage} &\PrintImage{6cm}{2cm}{yourimage} & \PrintImage{6cm}{2cm}{yourimage} \tabularnewline[\extraspaceforcutting]
\end{tabular}
\end{document}
Variante mit Schlaufe
\documentclass{article}
\usepackage[a4paper,lmargin=0.5cm,rmargin=0.5cm,tmargin=0.2cm,bmargin=0.2cm]{geometry}
\usepackage{forloop}%
\usepackage{etoolbox}%
\usepackage[demo]{graphicx}
\usepackage{calc}
\usepackage{ifthen}
\newlength{\oH}
\newlength{\oW}
\newlength{\rH}
\newlength{\cH}
\newcommand\PrintImage[3]{% width, height, image
\settototalheight{\oH}{\includegraphics{#3}}%
\settowidth{\oW}{\includegraphics{#3}}%
\setlength{\rH}{\oH * \ratio{#1}{\oW}}
\ifthenelse{\lengthtest{\rH < #2}}{
\includegraphics[width=#1]{#3}%
}{%
\setlength{\cH}{(\rH-#2)*\ratio{\oW}{#1}}%
\includegraphics[width=#1,clip,trim=0 \cH{} 0 0]{#3}%
}%
}%
\newcounter{rowcounter}
\newcounter{columncounter}
\newcounter{maxcolumns}
\newcounter{maxrows}
\setcounter{maxcolumns}{3}
\setcounter{maxrows}{9}%
\newlength{\extraspaceforcutting}
\setlength{\extraspaceforcutting}{0.2ex}
\begin{document}
\begin{tabular}{*{\value{maxcolumns}}{@{}c@{}}}
\forloop{rowcounter}{1}{\value{rowcounter} < \numexpr\value{maxrows}}{%
\forloop{columncounter}{1}{\value{columncounter} < \numexpr\value{maxcolumns}+1}{%
\PrintImage{6cm}{2cm}{yourimage} \ifnumless{\value{columncounter}}{3}{&}{}%
}%
\ifnumless{\value{rowcounter}}{\value{maxrows}-1}{\tabularnewline[\extraspaceforcutting]%
}{} % no newline
}%
\end{tabular}
\end{document}