# Resizing image and losing quality

I want to create a pdf document from images of different size and I fit each image to the text dimensions to include them in the document, with

``````\includegraphics[width=\textwidth, height=\textheight, keepaspectratio]{file.jpg}
``````

The problem is that these images are very enormous: 160MB in total; and this size is kept in the pdf output (160.9MB), but I don't need so much pixel information since I resize each image.

How can I exploit the resizing of each image to earn space?

-
Instinct tells me that LaTeX is not an image/graphics editor, and usually just dumps the image content in the output without modification. As such, some preprocessing using an external application is your best bet (for example, GIMP or Imagemagick). –  Werner Feb 26 '13 at 17:29
In addition to resample/resizing (using external tools as Werner suggested) I would also change the jpeg quality. Reducing it to 75% is usually few noticeable (specially on screen), and reduces dramatically the image size. –  JLDiaz Feb 26 '13 at 17:41

As the other suggested you can do some pre-processing on your images. This can be done with any tool you're comfortable with that can batch-process several files at once.

If you use ConTeXt you can hook this into the graphic inclusion routine very easily. Probably you can do this in LaTeX as well. Here is an example which uses graphicsmagick to reduce the image size and compress the image.

``````\startluacode
figures.converters.jpg = {
os.execute(string.format('gm convert -size 80%% -quality 20%% "%s" "%s"',oldname,newname))
end
}
\stopluacode

\starttext
%% unmodified inclusion
\externalfigure [hacker]

%% reduced size and higher compression