0

I want to crop an image but I don't want to define how much should be croped but how much should be left. The idea is if I have a command \pic{lines=5,path=picture.jpg} I want to only show the bottom (or top) part of the picture where this part shall be 5\baselineskip high. The width shall be untouched. I want to use that in a multicolumn environment. Right now I tried the following:

\documentclass{scrbook}
\usepackage[Export]{adjustbox}
\usepackage{multicol}
\usepackage{graphicx}
\usepackage{calc}
\RequirePackage{expl3}
\RequirePackage{xparse}

\ExplSyntaxOn
\keys_define:nn {pic}
{
path .tl_set:N = \l_path,
lines .fp_set:N = \l_lines,
}

\DeclareDocumentCommand\pic{m}{
\group_begin:
\IfNoValueF {#1} { \keys_set:nn {pic} {#1} }
\fp_set:Nn \l_lineheight {\fp_eval:n {\baselineskip*\fp_use:N \l_lines }}
\newlength{\help}
\setlength{\help}{\heightof{\includegraphics{\l_path}}}
\fp_set:Nn \l_picheight {\help}
\fp_compare:nNnTF {\l_lineheight}<{\l_picheight}
{
  \fp_set:Nn \l_help {\fp_eval:n {\l_picheight-\l_lineheight}}
  \noindent\includegraphics[trim=0 0 0 \l_help,clip]{\l_path}
}
{  
  \noindent\includegraphics{\l_path}
}
\group_end:
}

\ExplSyntaxOff

\begin{document}
\begin{multicols}{2}
Some Text
\pic{lines=5,path={example.jpg}}
\end{multicols}
\end{document}

This works but only if I know how much I want to trim. Also it trims top and right as well for a reason I don't know. The condition is necessary because later I want to do something else if lines*\baselineskip exceeds the height of the picture.

1 Answer 1

0

Question closed: I found a solution with putting the \includegraphics[trim=0 0 0 \l_help,clip]{\l_path} outside ExplySyntaxOn/Off in a extra command.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .