I want to crop images (which can be done by the option 'trim = l b r t'). This means I need to know the absolute size (in points or cm or inch ...) to set the parameters for the option 'trim'.
I can look at the image for the real size, but it is not convenient because I have a lot of images. Does anyone know how to get image size by code? something like \textwidth for width of text
many thanks, Hai
Graphics, Figures & Tables ⇒ How to get image size by code (to crop it)
NEW: TikZ book now 40% off at Amazon.com for a short time.

How to get image size by code (to crop it)
I found the answer
- add a new length command:
Code: Select all
\newlength{\imagewidth} % the name can be chosen, e.g. picwidth...
- Before using \imagewidth, set the width of image to it by
Code: Select all
\settowidth{\imagewidth}{\includegraphics{yourimage}}
- When using in calculation, remember to add {}, like this \imagewidth{}:
Code: Select all
\includegraphics[trim = 0 0 0.5\imagewidth{} 0, clip=true, width=4cm]{yourimage} % get the left part of your image