Fotografias de passaporte usando redimensionamento

Fotografias de passaporte usando redimensionamento
\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}

Usando este código, você pode criar uma fotografia de passaporte de 2x2 polegadas. Se estivermos usando papel A4, como podemos organizar a fotografia em colunas para que várias fotografias de passaporte possam ser geradas em uma página e o papel fotográfico não seja desperdiçado? Apenas por curiosidade e diversão.

Responder1

Que tal usar um tabular environment, a ordem precisa depende do tamanho do papel fotográfico?

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

insira a descrição da imagem aqui

Versão com loop

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

informação relacionada