[SOLVED]Help: creating contactsheet with imagemagic's montage

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
t-boz
Posts: 5
Joined: 2016-09-21T05:35:29-07:00
Authentication code: 1151

[SOLVED]Help: creating contactsheet with imagemagic's montage

Post by t-boz »

Hello everyone.
So I created contact sheet with image thumbnails, their filename and image sizes with the following command:

Code: Select all

montage -verbose -label '%wx%h\n%t' -font Helvetica -pointsize 10 -background '#FFFFFF' -fill 'gray'  -geometry 200x200+2+2 -auto-orient  *.jpg out.jpg
however when I run the script in the directory with A LOT of huge (in size) .jpg files, I quickly get out of memory, and entire computer freezes.
Adding -define jpeg:size=200x200 helps, however then incorrect image's sizes are added to label (width x height), and it's important that I have ORIGINAL image sizes on the final contact sheet.

Any help would be greatly appreciate!
Last edited by t-boz on 2016-09-21T16:41:21-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Help: creating contactsheet with imagemagic's montage

Post by snibgo »

I would do the job in stages, using a temporary directory.

1. Create or empty the temp dir.

2. Convert each source file, labelling and resizing, to the temp dir. Run "convert" once per source file. Or perhaps you could do this with "mogrify".

3. Montage the temp dir files.
snibgo's IM pages: im.snibgo.com
t-boz
Posts: 5
Joined: 2016-09-21T05:35:29-07:00
Authentication code: 1151

Re: Help: creating contactsheet with imagemagic's montage

Post by t-boz »

thanks for the reply!

How would I then complete all into one single contact sheet image? Can you show on a simple example?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Help: creating contactsheet with imagemagic's montage

Post by Bonzo »

There are different ways you could do it; I do not use mogrify but something like this might work but you would need two steps.

Code: Select all

mogrify -label '%wx%h\n%t' -font Helvetica -pointsize 10 -fill 'gray'  -background '#FFFFFF' -geometry 200x200+2+2 -auto-orient  -format miff *.jpg
This should leave your original jpg images intact and save as a lossless format - make sure you test on some copy images as mogrify can overwrite the original.

Code: Select all

montage *.miff out.jpg
You could also write a shell/batch script and loop over each image with convert.
t-boz
Posts: 5
Joined: 2016-09-21T05:35:29-07:00
Authentication code: 1151

Re: Help: creating contactsheet with imagemagic's montage

Post by t-boz »

thanks so much for replying, but sadly it doesn't solve my problem at all.
yes, covert works, and fine (though image files only increase in size)

however when running a command to generate the contact sheet

Code: Select all

montage *.miff out.jpg
I face the same problem. Imagemagick will read each file and keep the full size image in memory until montage is done. And with *.miff the size only increased, so it doesn't help at all, and I get stuck/memory full/computer frozen (please note, I have to run the bash script to create contact sheets against folders of hunderds of uncompressed .jpg files, sometimes each .jpg file over 100 MB. Of course when I have a folder with only 20-30 images (even large in size), it's all fine. But when there are over 100, that's when the problems begin)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Help: creating contactsheet with imagemagic's montage

Post by snibgo »

You are first reducing them down to 200x200 before reading them into montage, yes? So it doesn't matter how large the source images are?
snibgo's IM pages: im.snibgo.com
t-boz
Posts: 5
Joined: 2016-09-21T05:35:29-07:00
Authentication code: 1151

Re: Help: creating contactsheet with imagemagic's montage

Post by t-boz »

snibgo wrote:You are first reducing them down to 200x200 before reading them into montage, yes? So it doesn't matter how large the source images are?
no, not reducing them, if I do then the '%wx%h' label would give incorrect information about the image sizes. (if I add the -define jpeg:size=200x200 option, as stated in the original post)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Help: creating contactsheet with imagemagic's montage

Post by snibgo »

Well, as they don't all fit into memory at once, I'm suggesting you first resize and label one at a time. Then montage these smaller images together.

The command that resizes and labels one image could be something like:

Code: Select all

convert $LOOPVAR -set option:mylabel "%wx%h\n%t" -resize 200 -gravity center label:"%[mylabel]" -append newdir/$LOOPVAR
snibgo's IM pages: im.snibgo.com
t-boz
Posts: 5
Joined: 2016-09-21T05:35:29-07:00
Authentication code: 1151

Re: Help: creating contactsheet with imagemagic's montage

Post by t-boz »

thanks, this solution works perfectly well, resizing them with proper labels for each ina loop and then just making a montage. Great,thanks!
Post Reply