tags:

views:

894

answers:

3

I have many pictures which size differ much from picture to picture.

I aim to develop an algorithm which allows you to remove the extra whitespace. Such algorithms are used in Signal Processing in removing the redundant noise, for instance in mobile phones.

The algorithm should be used as follows

 \includegraphics[crop-redundant-whitespace]{picture.png}

The function crop-redundant-whitespace should change the include -command, for instance to

 \includegraphics[width=2.5cm, height=5.0cm]{picture.png}

The algorithm should

  • detect parts of size at least 2cm in length which are separate from each other
  • if many large parts exist, then the biggest part should be selected.

How can you automatically resize pictures and make them fix to A4?

+1  A: 

Rough and ready:

\documentclass[a4paper]{article}

\begin{document}
\resizebox{\textwidth}{\textheight}{\includegraphics*{compatible_image_file}}
\end{document}

but you'll lose the aspect ratio. Replace one or the other length with "!" to preserve the ratio. You could also stick a \rotatebox around the whole graphics include to fix a portrait/landscape incompatibility.

Using the square-bracket style arguments to \includegraphics, would look like:

\includegraphics[width=\textwidth, height=\textheight]{compatible_image_file}

which is probably more up-to-date than the creaking ancient cantrip that I've been lugging around for 15 years. Must update my personal bog-o-tricks file...

The usual margin diddling is applicable if you find the default whitespace to be too expansive. And you might consider using the slides class. I think the default margins are closer to the edge of the page.

dmckee
Thank you for the tip! - However, your solution does not remove the extra whitespace around the picture.
Masi
No, it doesn't. It only answer the question you originally wrote.
dmckee
+2  A: 

This isn't really a LaTeX question; it is possible to execute arbitrary conversions on images you include in the document but detecting whitespace in an image, say, is very very far away from LaTeX's useful range of abilities.

Work out how to do it with ImageMagick or whatever, and then ask how to interface that with LaTeX.

Will Robertson
@Will: This is a solution: http://pdfcrop.sourceforge.net/ . The pictures need to be converted first to PDF, and then pdfcrop automatically resizes the pictures. It is now a LaTeX -question. How can you bind the PdfCrop to a image -command in LaTeX.
Masi
+1  A: 

You can perform arbitrary conversions on images with the shell-escape feature of epstopdf. Here's an example of pdfcrop being executed on each PDF file that is included:

\documentclass{article}
\usepackage{graphicx,epstopdf}
\DeclareGraphicsRule{.pdf}{pdf}{-crop.pdf}{`pdfcrop #1}
\begin{document}
\fbox{\includegraphics[scale=0.5]{essai}}% => change this to a real PDF
\end{document}

However, I'm having trouble getting this in a pre-release version of TeX Live 2009; can't spend any time debugging now but see how you go on any older system.

Even if this works fine for you, this is pretty inefficient since it has to run every time the document is compiled. I'd suggest just preprocessing your images.

Will Robertson
I have the same problem in OS X Leopard and TextLive 2008.
Masi
Works for me with TeX Live 2008. Do you have -shell-escape turned on?
Will Robertson