Discussion:
Memory Increase
Maria-Teresa Nunez-Pardo-de-Vera
2010-09-22 07:41:12 UTC
Permalink
Hello,
I am using the ImageMagick library for storing images from
a CCD Camera in tif format. The problem that I have is that every
call to the function:

Image::write

increase the memory consuption of the program, up to the point when
the computer is collapsed and one need to reboot it.
Could be possible to have a solution to this problem?.
Thank you very much in advance.

Best Regards,
Teresa Nunez
Wolfgang Hugemann
2010-09-23 11:07:52 UTC
Permalink
Hello,

I combined a bunch of JPEGs to a PDF via

convert *.jpg JPEGs.pdf

BTW: Filename globbing via wildcards works perfect on my Windows computer, in contrast to the documentation http://www.imagemagick.org/script/command-line-processing.php which claims this to function only for UNIX shells (?).

However, when I extracted the files losslessly from the PDF with the help of PDFimages (http://www.foolabs.com/xpdf/download.html), the JPEGs were slighty different from the originals. They report the same dimensions and JPEG-quality, but they don't have exactly the same size.

I suspect that ImageMagick somehow re-encoded the JPEGs before it wrapped them into the PDF.
Is there a way to tell ImageMagick to leave the JPEGs as they are and just to wrap them into a PDF?

Wolfgang Hugemann
Glenn Linderman
2010-09-23 17:37:44 UTC
Permalink
Post by Maria-Teresa Nunez-Pardo-de-Vera
Hello,
I combined a bunch of JPEGs to a PDF via
convert *.jpg JPEGs.pdf
BTW: Filename globbing via wildcards works perfect on my Windows computer, in contrast to the documentation http://www.imagemagick.org/script/command-line-processing.php which claims this to function only for UNIX shells (?).
Is it Windows or convert that is expanding your glob for you? In that
same directory, try

echo *.jpg

and see how many files are listed.
Post by Maria-Teresa Nunez-Pardo-de-Vera
However, when I extracted the files losslessly from the PDF with the help of PDFimages (http://www.foolabs.com/xpdf/download.html), the JPEGs were slighty different from the originals. They report the same dimensions and JPEG-quality, but they don't have exactly the same size.
So is the difference in the image blob, or in the EXIF tags (which might
get stripped on the way in to the PDF?)? How different is the size (a
few bytes? 10%? or ?)?
Post by Maria-Teresa Nunez-Pardo-de-Vera
I suspect that ImageMagick somehow re-encoded the JPEGs before it wrapped them into the PDF.
You might be right, because IM tends to decompress images to full
bitmaps before doing pretty much anything to them.
Post by Maria-Teresa Nunez-Pardo-de-Vera
Is there a way to tell ImageMagick to leave the JPEGs as they are and just to wrap them into a PDF?
Wolfgang Hugemann
Wolfgang Hugemann
2010-09-25 18:16:07 UTC
Permalink
Post by Glenn Linderman
Is it Windows or convert that is expanding your glob for you? In that
same directory, try
echo *.jpg
and see how many files are listed.
I can't tell; I just note that it's working. The command line above does
not work under Windows; it will just echo the exact string, i.e.
"*.jpp". But you can do things like 'dir *.jpg' and Windows will list
all files with the extension "jpg".
Post by Glenn Linderman
So is the difference in the image blob, or in the EXIF tags (which might
get stripped on the way in to the PDF?)? How different is the size (a
few bytes? 10%? or ?)?
The difference in size is only very slight, about 1%, and it is not due
to excessive data being stripped off. The image content is actually
slightly different. I compared the two images via

convert original.jpg extracted.jpg -compose difference -composite
comparison.png

and then counted the colours.
Post by Glenn Linderman
Post by Wolfgang Hugemann
I suspect that ImageMagick somehow re-encoded the JPEGs before it wrapped them into the PDF.
You might be right, because IM tends to decompress images to full
bitmaps before doing pretty much anything to them.
Post by Wolfgang Hugemann
Is there a way to tell ImageMagick to leave the JPEGs as they are and just to wrap them into a PDF?
It would be great if there would be a "preserve" option or alike. When
combining several JPEGs to a PDF, there really is no use in re-encoding
the JPEGs if you apply no modifications to them.

I checked with Adobe Acrobat and it does the trick of merging several
JPEGs to one PDF, with the extracted JPEGs being exactly identical to
their originals. There also seems to be other proprietary software that
does the trick of bulk-converting JPEGs to PDF, but no freeware tool.
The populat PDFsam does not take other formats than PDF as input.

Wolfgang Hugemann
Glenn Linderman
2010-09-25 21:45:11 UTC
Permalink
Post by Wolfgang Hugemann
Post by Glenn Linderman
Is it Windows or convert that is expanding your glob for you? In that
same directory, try
echo *.jpg
and see how many files are listed.
I can't tell; I just note that it's working. The command line above does
not work under Windows; it will just echo the exact string, i.e.
"*.jpp". But you can do things like 'dir *.jpg' and Windows will list
all files with the extension "jpg".
So if it were the Windows shell doing the expansion, it would happen
even for the echo command, is the point, and such does happen on Unix.
On Windows, each command or program that wants to deal with glob
expansion has to do it itself. Some do, some don't.
Post by Wolfgang Hugemann
Post by Glenn Linderman
So is the difference in the image blob, or in the EXIF tags (which might
get stripped on the way in to the PDF?)? How different is the size (a
few bytes? 10%? or ?)?
The difference in size is only very slight, about 1%, and it is not due
to excessive data being stripped off. The image content is actually
slightly different. I compared the two images via
convert original.jpg extracted.jpg -compose difference -composite
comparison.png
and then counted the colours.
A difference in color count does indicate a difference in image content
(although the same color count would not prove identical image
content). So you have proven that ImageMagick is expanding and
recompressing the images in this particular case, which is typical of
its processing style.
Post by Wolfgang Hugemann
Post by Glenn Linderman
Post by Wolfgang Hugemann
I suspect that ImageMagick somehow re-encoded the JPEGs before it wrapped them into the PDF.
You might be right, because IM tends to decompress images to full
bitmaps before doing pretty much anything to them.
Post by Wolfgang Hugemann
Is there a way to tell ImageMagick to leave the JPEGs as they are and just to wrap them into a PDF?
It would be great if there would be a "preserve" option or alike. When
combining several JPEGs to a PDF, there really is no use in re-encoding
the JPEGs if you apply no modifications to them.
Not only is there no benefit to the re-encoding, there are actually two
problems that result: it takes more processor power, and every
re-encoding loses a bit of quality.
Post by Wolfgang Hugemann
I checked with Adobe Acrobat and it does the trick of merging several
JPEGs to one PDF, with the extracted JPEGs being exactly identical to
their originals. There also seems to be other proprietary software that
does the trick of bulk-converting JPEGs to PDF, but no freeware tool.
The populat PDFsam does not take other formats than PDF as input.
Wolfgang Hugemann
2010-09-27 12:29:05 UTC
Permalink
Post by Glenn Linderman
Post by Wolfgang Hugemann
The difference in size is only very slight, about 1%, and it is not due
to excessive data being stripped off. The image content is actually
slightly different. I compared the two images via
convert original.jpg extracted.jpg -compose difference -composite
comparison.png
and then counted the colours.
A difference in color count does indicate a difference in image content
(although the same color count would not prove identical image
content).
You misunderstood me:
I counted the colours in comparison.png, which is 1 if the two images
are identical. (This is the result I get when I combine the JPEGs with
Acrobat and then extract them with pdfimages.)
Post by Glenn Linderman
Not only is there no benefit to the re-encoding, there are actually two
problems that result: it takes more processor power, and every
re-encoding loses a bit of quality.
Well, that's why I'm asking all this ;-)

Greetings from Münster, germany
Wolfgang Hugemann
geo cherchetout
2010-09-25 19:40:45 UTC
Permalink
Post by Wolfgang Hugemann
It would be great if there would be a "preserve" option or alike. When
combining several JPEGs to a PDF, there really is no use in re-encoding
the JPEGs if you apply no modifications to them.
+1

I wrote the same thing on 10-24-2009...
Post by Wolfgang Hugemann
I checked with Adobe Acrobat and it does the trick of merging several
JPEGs to one PDF, with the extracted JPEGs being exactly identical to
their originals. There also seems to be other proprietary software that
does the trick of bulk-converting JPEGs to PDF, but no freeware tool.
You can use pdflatex, a true free software, but it is *a few* more
complicated since it needs you to write a source text and then compile it.
John Culleton
2010-09-25 22:16:20 UTC
Permalink
Post by geo cherchetout
Post by Wolfgang Hugemann
It would be great if there would be a "preserve" option or alike.
When combining several JPEGs to a PDF, there really is no use in
re-encoding the JPEGs if you apply no modifications to them.
+1
I wrote the same thing on 10-24-2009...
Post by Wolfgang Hugemann
I checked with Adobe Acrobat and it does the trick of merging
several JPEGs to one PDF, with the extracted JPEGs being exactly
identical to their originals. There also seems to be other
proprietary software that does the trick of bulk-converting JPEGs
to PDF, but no freeware tool.
You can use pdflatex, a true free software, but it is *a few* more
complicated since it needs you to write a source text and then
compile it.
Pdftex is a bit simpler.
--
John Culleton
Wexford Press
"Create Book Covers with Scribus"
Printable E-book 38 pages $5.95
http://www.booklocker.com/books/4055.html
Wolfgang Hugemann
2010-09-27 12:37:05 UTC
Permalink
Post by geo cherchetout
I wrote the same thing on 10-24-2009...
Sorry, I missed that one. I have just read it. Thanks also for the
readymade LaTeX code, which I can easily use, because I work a lot with
LaTeX.

We, however, have to admit one command line in IM would be an easier way
to perform this task. I also appreciate that IM equals the page size to
the image size, which makes viewing things on the screen a lot easier.

Wolfgang Hugemann

Loading...