크기 조정을 사용한 여권 사진

크기 조정을 사용한 여권 사진
\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}

이 코드를 사용하면 2x2인치 여권 사진을 만들 수 있습니다. A4 용지를 사용하는 경우 한 페이지에 여러 장의 여권 사진을 생성하고 인화지가 낭비되지 않도록 사진을 열로 배열하려면 어떻게 해야 합니까? 단지 호기심과 재미를 위해서입니다.

답변1

표 형식을 사용하는 것은 어떻습니까 environment? 정확한 순서는 인화지 크기에 따라 다릅니다.

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

여기에 이미지 설명을 입력하세요

루프가 있는 버전

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

관련 정보