Montage output multiple files when pixel limit met

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?".
tuggleg
Posts: 16
Joined: 2017-05-01T08:57:40-07:00
Authentication code: 1151

Montage output multiple files when pixel limit met

Post by tuggleg »

Hello,
I use image magick montage to create 'contact sheets' for my photography team. From time to time the total number of images exceeds the pixel dimension limitation and the script 'fails', creating no image. Here is my current code:

Code: Select all

montage -verbose -label %t -pointsize 25 -background '#FFFFFF' -tile 15x$contactSheetRows -fill 'black' -define jpeg:size=600x780 -geometry 600x780+40+150 -quality 90 -auto-orient $dailyImages.FullName E:\Contact_Sheet.jpg
When the pixel dimension limitation is met, I would like for the script to output the maximum # of images/pixels and then continue to create additional outputs with the remaining images. I was hoping there was a single operator for montage that could handle this.

In this thread (viewtopic.php?t=27973) user @snibgo claims 'Yes, ImageMagick montage will create as many output images as required', but that has not been my experience.

What am I missing?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Montage output multiple files when pixel limit met

Post by snibgo »

What is the value of $contactSheetRows ? In that thread, we were talking about having more images than "-tile XxY", not hitting a pixel limit. I suggest you ensure that $contactSheetRows is reasonably low. Then if you have more than 15*contactSheetRows montage will create more contact sheets are needed.
snibgo's IM pages: im.snibgo.com
tuggleg
Posts: 16
Joined: 2017-05-01T08:57:40-07:00
Authentication code: 1151

Re: Montage output multiple files when pixel limit met

Post by tuggleg »

$contactSheetRows will be equivalent to the number of total images for each contact sheet divided by 15. My logic was that 15 columns was 'aesthetically pleasing' and I didn't want blank rows.

It sounds like you are suggesting that I have created my own limitations by doing this, and that if I do not set such parameters it will default to create multiple sheets. If that is the case should I remove the entire '-tile 15x$contactSheetRows' bit of code?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Montage output multiple files when pixel limit met

Post by snibgo »

What version of IM? On what platform?

What error message do you get?

You have "-tile 15x$contactSheetRows". This is 15 columns and some number of rows.
tuggleg wrote:...15 rows was 'aesthetically pleasing'
It may be, but you haven't asked for 15 rows.

Suppose you have 300 images. Then I suppose you will have "-tile 15x20", which will make a grid of images 15 wide by 20 high. Fair enough. Each image will be 600x780 pixels. So the final image on one contact sheet will be 9000x17400 pixels. This might need 8 bytes per pixel, so about 1.25 GB for each of the input and output, and your computer can probably handle this.

But if you have 3000 images, you need ten times as much memory, and perhaps your computer can't handle that. (You haven't said what error message you get.)

I suspect you need to set an upper limit to contactSheetRows such that you don't try to create very large images.
snibgo's IM pages: im.snibgo.com
tuggleg
Posts: 16
Joined: 2017-05-01T08:57:40-07:00
Authentication code: 1151

Re: Montage output multiple files when pixel limit met

Post by tuggleg »

Snibgo, I made a correction to my last response. I was referring to creating a contact sheet that is 15 images across and the number of rows would be determined by the total number of images divided by 15. For instance if there's 60 images, 60/15= 4, so 4 rows of 15 images. Sorry for the confusion.

We are working in PowerShell on Windows 10 using IM v7.0.3. The machines are powerful but it may be a performance issue as you suggested. I haven't been able to capture the error as I run the script off the production machines via Group Policy or Task Scheduler at log out with the PowerShell window hidden. I only know of the failure when the output is not present, this generally occurs when there is a large number of images (~3000). I will try to re-create the problem and report back.

Thanks
tuggleg
Posts: 16
Joined: 2017-05-01T08:57:40-07:00
Authentication code: 1151

Re: Montage output multiple files when pixel limit met

Post by tuggleg »

I recreated the error by incrementally adding more images to the source folder until the script failed and produced the following error, 'Program 'montage.exe' failed to run: The filename or extension is too long'.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Montage output multiple files when pixel limit met

Post by snibgo »

Ah, well, so montage isn't failing. It isn't even running.

I suggest you modify the script to show the command line. I guess the problem is in $dailyImages.FullName.
snibgo's IM pages: im.snibgo.com
tuggleg
Posts: 16
Joined: 2017-05-01T08:57:40-07:00
Authentication code: 1151

Re: Montage output multiple files when pixel limit met

Post by tuggleg »

OK, I can look into that. Does that really explain why everything worked fine all the way up to X number of images and then resulted in this error when it was X+1? The only thing that changed between successful and unsuccessful runs was the addition of a few more images to the source. $dailyimages.Fullname is just a variable for the images.

Code: Select all

$dailyImages = Get-ChildItem -Path $dailyPhotoBay -Include *.jpg -Recurse
Not sure if you are familiar with PowerShell, but that is the line right above the previous code I shared.

EDIT* - I guess maybe with the new files the string of all the files was too long. That makes sense. Do you agree?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Montage output multiple files when pixel limit met

Post by snibgo »

tuggleg wrote:I guess maybe with the new files the string of all the files was too long. That makes sense. Do you agree?
Yes, that's my guess. You might echo or print that variable.

The syntax of "montage" is for a space-separated list of filenames, or a single filename prefixed with "@". The file is text, a list of filenames separated by spaces or newlines. This keeps the command line short. So for this problem, I suggest you send the list to a file, then use "@".
snibgo's IM pages: im.snibgo.com
tuggleg
Posts: 16
Joined: 2017-05-01T08:57:40-07:00
Authentication code: 1151

Re: Montage output multiple files when pixel limit met

Post by tuggleg »

Can you describe how to use the '@'?

I have all the filename paths written to a text document now, $contactSheetFiles. The paths are separated by new lines like so:
E:\Output\Image1.jpg
E:\Output\Image2.jpg
E:\Output\Image3.jpg

Then I use similar code as before

Code: Select all

montage -verbose -label %t -pointsize 25 -background '#FFFFFF' -tile 15x$contactSheetRows -fill 'black' -define jpeg:size=600x780 -geometry 600x780+40+150 -quality 90 -auto-orient $contactSheetFiles E:\Contact_Sheet.jpg
This works fine until I start bumming up the number of images and once I hit a certain point, the same error occurs. I am not using the '@' since you said that's only needed for single files, should I be using that? If so can you describe how?

Thanks again for all the help on this.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Montage output multiple files when pixel limit met

Post by snibgo »

When you use $-prefix, your shell (PowerShell) translates the variable, expanding it to a long list. This makes the command long, and that's a problem.

Instead, you can write all the filenames to a text file. (I don't know how to do this in PowerShell.) PowerShell will pass that parameter (the name of the single text file, prefixed with "@", like @filename.txt) to montage, and the expansion will occur within montage, not the shell.

Suppose you call the file "mylist.txt". Then mylist.txt might contain:

Code: Select all

E:\Output\Image1.jpg
E:\Output\Image2.jpg
E:\Output\Image3.jpg
Then your command would be:

Code: Select all

montage -verbose -label %t -pointsize 25 -background '#FFFFFF' -tile 15x$contactSheetRows -fill 'black' -define jpeg:size=600x780 -geometry 600x780+40+150 -quality 90 -auto-orient @mylist.txt E:\Contact_Sheet.jpg
snibgo's IM pages: im.snibgo.com
tuggleg
Posts: 16
Joined: 2017-05-01T08:57:40-07:00
Authentication code: 1151

Re: Montage output multiple files when pixel limit met

Post by tuggleg »

Thanks again for all your help, I am still having issues using the '@' operator. It may be conflicting with the PowerShell language etc. I opened a thread on Stack Overflow for more specific help with PowerShell. If you have time to give it a look it may help better explain my issue.

When using the '@' operator, I am receiving errors:
montage : montage.exe: unable to open image '@E:ÿþE': No such file or directory @ error/blob.c/OpenBlob/2695.
montage.exe: no decode delegate for this image format `' @ error/constitute.c/ReadImage/508.
montage.exe: `E:\Contact_Sheet.jpg' @ error/montage.c/MontageImageCommand/1774.

I have tried a few different ways, but haven't been able to nail it down yet. Thanks again for all your help.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Montage output multiple files when pixel limit met

Post by snibgo »

I opened a thread on Stack Overflow for more specific help with PowerShell. If you have time to give it a look it may help better explain my issue.
Link?
snibgo's IM pages: im.snibgo.com
tuggleg
Posts: 16
Joined: 2017-05-01T08:57:40-07:00
Authentication code: 1151

Re: Montage output multiple files when pixel limit met

Post by tuggleg »

Woops, sorry about that: https://stackoverflow.com/questions/519 ... -text-file

There are a few options i thought of this morning, perhaps piping the document into the montage command will relieve the errors.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Montage output multiple files when pixel limit met

Post by snibgo »

If you show your Powershell script, or the contents of E:\Output\contactSheetImages.txt, I can't find them.

I don't know the Powershell escaping rules. Maybe "\" needs to be escaped.

I suggest you arrange files so your montage command doesn't need drives or directories, and nor do the files listed in contactSheetImages.txt. When that works, add drives and directories (if needed) one at a time.
snibgo's IM pages: im.snibgo.com
Post Reply