I've written a small TeX-file in order to include very quick a large
number of pictures with a caption and an index in one document.
pictures from digital cameras are usually very large and the
pdf-document would be very large then. So I've thought I could process
the pictures before I include them automatically e.g. with imagemagic
(or any other tool) to downsize the picture size and then include the
picture in the pdf-document. The original picture should be left
unchanged. the temporary (now smaller) picture should not be stored but
included in the document.
In the LaTeX Companion (german edition) there is a sample how to
processa files with the help of gzip on the fly.
My problem is that LaTeX knows about the picture size but cannot handle
the transfered picture which is sent to STDOUT. The command
convert -debug all -quality 80 #1 test.jpg
produces a smaller picture. The comand issued at the shell prompt
convert -debug all -quality 80 #1-
deliveres the picture to STDOUT. Debug messages from ImageMagic are not
found in the LaTeX logfile.
The LaTeX Logfile shows the following:
--8<---if--you--cut--here--you--will--probably--destroy--your--monitor--
This is pdfeTeX, Version 3.141592-1.21a-2.2 (MiKTeX 2.4) (preloaded
format=latex 2008.11.15) 12 JUN 2010 17:07
entering extended mode
**minimalbeispiel.tex
(minimalbeispiel.tex
LaTeX2e <2003/12/01>
Babel <v3.8g> and hyphenation patterns for english, dumylang,
nohyphenation, ge
rman, ngerman, danish, french, polish, loaded.
(C:\programme\office\TeXLive\texmf\tex\latex\base\article.cls
Document Class: article 2004/02/16 v1.4f Standard LaTeX document class
(C:\programme\office\TeXLive\texmf\tex\latex\base\size12.clo
File: size12.clo 2004/02/16 v1.4f Standard LaTeX file (size option)
[...]
\tf@lop=\write4
<test01.jpg, id=1, 2569.6pt x 1927.2pt>
File: 'convert -debug all -quality 80 test01.jpg- Graphic file (type
jpg)
<use 'convert -debug all -quality 80 test01.jpg-> [1
{psfonts.map}]
(minimalbeispiel.aux) )
[...]
Output written on minimalbeispiel.pdf (1 page, 62488 bytes).
--8<---if--you--cut--here--you--will--probably--destroy--your--monitor--
Here is a basic sample. For the picture, just use a jpg file of your
choice and name it test01.jpg.
--8<---if--you--cut--here--you--will--probably--destroy--your--monitor--
\documentclass[a4paper,pdftex,12pt]{article}
% Vorlagenname: minimalbeispiel.tex
\usepackage{german} % deutsche Trennmuster, letzte Seite referenzieren
\usepackage[latin1]{inputenc} % Latin1 Zeichensatzkodierung verwenden
\usepackage[T1]{fontenc} % T1-Fontencoding verwenden
\usepackage{graphicx} % Grafiken einbinden
\usepackage[dvipsnames,usenames]{color} % Farben verwenden
\usepackage{float} % Eigene Gleitobjekte erstellen
\floatstyle{plain} % plain
\newfloat{Bilder}{H}{lop} % Dateierweiterung lop: List of Pictures
\floatname{Bilder}{Bild} % Benennung der Unterschrift
\DeclareGraphicsExtensions{.jpg}
%\DeclareGraphicsRule{.jpg.gz}{jpg}{}{`gunzip -c #1} % Beispiel LaTeX
%Companion
%\DeclareGraphicsRule{.jpg}{jpg}{.jpg}{'convert -colorspace gray #1-}
\DeclareGraphicsRule{.jpg}{jpg}{.jpg}{`convert -quality 80 #1-}
\newcommand{\bild}[2]{%
% Parameter 1: das Bild - Parameter 2: die Bildunterschrift
\begin{Bilder}%
\includegraphics*[width=13cm]{#1}
\caption{\textbf{(#1) #2}}
\end{Bilder}
}
\begin{document}
\title{Photo documentation}
%\author{Peter Seitz}
\date{23-Jul-2009}
\maketitle
\noindent
\listof{Bilder}{Bilderverzeichnis}
%Here come the pictures
\noindent
\bild{test01}{Picture Caption}
\end{document}
--8<---if--you--cut--here--you--will--probably--destroy--your--monitor--
If you comment out the Line \DeclareGraphicsRule, the picture will be
included.
I don't know on how to find out under windows if ma pdflatex driver
tries to run convert from imagemagic
Since the sample from the LaTeX Companion is very well known (it is
referenced by many sources), I'd like to know if anybody can confirm
that the sample works with the gzip program. Please tell which operating
system is used and which driver.
If I know that it runs with gzip, I can test it on my system and try to
make gzip run. Then the next step is to make convert from ImageMagic to run.
thanks for your comments
Peter Seitz
Not possible. LaTeX in effect requires the image to be in a disk file at
the time of typesetting, because that is where it reads the image
dimensions from.
> In the LaTeX Companion (german edition) there is a sample how to
> processa files with the help of gzip on the fly.
>
> My problem is that LaTeX knows about the picture size but cannot handle
> the transfered picture which is sent to STDOUT.
For the reason given. It might be possible to rearrange LaTeX's file
handles in the graphicx package so that it can successively read the
image dimensions from STDIN, provided (a) you feed the expected data to
the process in the right order; (b) you never create an error condition
where terminal input from the user would be expected via STDIN; and (c)
you use only traditional LaTeX-to-DVI, where the image binary data is
not included in the output, but referenced by filename (similar concept
to HTML).
However, this is a Catch-22: it may allow you to create a DVI file, but
by definition the image files will not be present at the end of the run,
so the DVI file will essentially be useless; if on the other hand you
use pdflatex, the image binary data is serialised into the output stream
at the end of processing, so you would additionally need to re-process
all the images at that time in order to feed that data to the process,
but to allow pdflatex to access that data via STDIN would probably mean
additional rewriting.
I suggest you write the resized images to disk and delete them after
running LaTeX. I'm not clear what the benefit would be of trying to do
it on the fly via STDIN.
///Peter
> I've written a small TeX-file in order to include very quick a large
> number of pictures with a caption and an index in one document.
> pictures from digital cameras are usually very large and the
> pdf-document would be very large then. So I've thought I could process
> the pictures before I include them automatically e.g. with imagemagic
> (or any other tool) to downsize the picture size and then include the
> picture in the pdf-document. The original picture should be left
> unchanged. the temporary (now smaller) picture should not be stored but
> included in the document.
>
> In the LaTeX Companion (german edition) there is a sample how to
> processa files with the help of gzip on the fly.
>
> My problem is that LaTeX knows about the picture size but cannot handle
> the transfered picture which is sent to STDOUT. The command
>
> convert -debug all -quality 80 #1 test.jpg
>
> produces a smaller picture. The comand issued at the shell prompt
>
> convert -debug all -quality 80 #1-
>
> deliveres the picture to STDOUT. Debug messages from ImageMagic are not
> found in the LaTeX logfile.
That will not work for pdfTeX, the example is for dvips only.
In case of pdfTeX you can use package `epstopdf' to call
convert inside the TeX run automatically:
\documentclass{article}
\usepackage{graphicx}
\usepackage{epstopdf}[2010/02/09]
\epstopdfDeclareGraphicsRule{.jpg}{jpg}{.jpg}{%
\epstopdfcall{`convert -quality 10 %
\noexpand\SourceFile\space\noexpand\OutputFile
}%
}
\begin{document}
\fbox{\includegraphics{bb}}
\end{document}
Then call pdflatex:
pdflatex -shell-escape test
Important hints:
* You need the latest version of epstopdf, especially option `suffix'
must be set (default for epstopdf 2010/02/09 v2.5). Otherwise the
source .jpg file is probably overwritten.
* Shell-escape must be enabled, otherwise `convert' can't be
executed.
Then `foo.jpg' is automatically converted to
`foo-jpg-converted-to.jpg'. And you can delete
these files afterwards.
--
Heiko Oberdiek