0

I am working on a PowerShell script using Image Magick's montage function. My script works until the source files (.jpgs) volume increases to an ambiguous number of files. Once there are 'too many' files, the script fails due to 'Program 'montage.exe' failed to run: The filename or extension is too long'. It was suggested on the Image Magick forum (link @ bottom) to have PowerShell read from a text doc instead to reduce the length using the '@' operator.

The code now looks like:

montage -verbose -label %t -pointsize 25 -background '#FFFFFF' -tile 24x5 -fill 'black' -define jpeg:size=600x780 -geometry 600x780+40+150 -quality 90 -auto-orient @E:\Output\contactSheetImages.txt E:\Contact_Sheet.jpg

I am getting the following 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 am fairly certain using the '@' operator as I have may be confusing the script, but I don't have enough understanding of using '@' in PowerShell to know why.

Can anyone with ImageMagick understanding, or simply a stronger PowerShell understanding explain why that may be breaking the script?

I have tried:

  • Replacing @E:\Output\contactSheetImages.txt with a variable to Get-Content from the txt file
  • Targeting the text doc without the '@' operator
  • Using single and double quotes around @E:\Output\contactSheetImages.txt

Image Magick Forum: https://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=34596

Garrett
  • 617
  • 12
  • 30
  • Please note, the image '@E:ÿþE' is not an image in my source directory nor is it listed anywhere in the text doc – Garrett Aug 20 '18 at 19:01
  • Does it work if you put single or double quotes about the `@E:\Output\contactSheetImages.txt`. It is possible the ImageMagick @ syntax does not recognize volume addresses. I am just not sure and do not use Windows. – fmw42 Aug 20 '18 at 19:35
  • @fmw42 , yes I tried that to no avail. Thanks for the suggestion! – Garrett Aug 20 '18 at 19:59
  • You could try `montage ... @- OutputFile.jpg < E:\Output\contactSheetImages.txt` so that **ImageMagick** is just reading a file from `standard input` (i.e. `@-`) and Windows has to worry about parsing and sending `E:\Output\contactSheetImages.txt` to its `stdin`. – Mark Setchell Aug 20 '18 at 20:47
  • 1
    You can express that the other way around too `TYPE E:\Output\contactSheetImages.txt | montage ... @- result.jpg` – Mark Setchell Aug 20 '18 at 20:57
  • Also note that you should check your ImageMagick policy.xml file to see if there is a restriction on using @. – fmw42 Aug 20 '18 at 22:55
  • @MarkSetchell I notice you are putting a '-' after the '@'. What is that? When I try to input standalone '@' or '@-' I immediately get an error – Garrett Aug 21 '18 at 17:43
  • The `@` means a filename containing a list of files will follow. The `-` means that list is actually being piped into the program. Try using `"@-"` or `backtick @-` – Mark Setchell Aug 21 '18 at 17:53
  • Or try `montage --% ...` to stop Powershell expanding `@` signs... https://ss64.com/ps/syntax-esc.html – Mark Setchell Aug 21 '18 at 17:58

1 Answers1

0

Thanks everyone for your ideas and help. While I wasn't able to use any of the provided ideas it allowed me to think up a simple solution.

I simply removed the need to read a text file by targeting the files directly:

montage -verbose -label %t -pointsize 25 -background '#FFFFFF' -tile 24x5 -fill 'black' -define jpeg:size=600x780 -geometry 600x780+40+150 -quality 90 -auto-orient E:\Output\*.jpg E:\Contact_Sheet.jpg

Although I would have liked to solve the problem instead of developing a work around, my script is now working.

Garrett
  • 617
  • 12
  • 30