Hint: Sorting filenames for Montage under Windows

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
User avatar
Posts: 259
Joined: 2011-03-28T07:11:31-07:00
Authentication code: 8675308
Location: Münster, Germany 52°N,7.6°E

Hint: Sorting filenames for Montage under Windows

Post by whugemann » 2018-06-22T00:21:28-07:00

A lot of PDF printers cut photos into horizontal stripes or even tiles. You can extract these sniplets with the help of the xpdf tools and re-combine them with Montage, preferably sending their filenames to a batch file via SendTo. However, the filenames are not sorted by name when sent. So how do you sort the command line parameters?


Code: Select all

SETLOCAL EnableDelayedExpansion
:: send the command line parameters (i.e. filenames) line-wise to a text file
:: and sort them
DEL list*.txt
For %%i in (%*) DO Echo %%i >> List.txt
SORT list.txt >list2.txt
:: you cannot  just hand over the list to Montage via @list2.txt
:: as this does not handle filenames with spaces correctly,
:: thus you have to assemble them in one line again.
:: The usual delimiters have to be blocked.
SET var=
FOR /f "delims=" %%i in (list2.txt) DO (
   SET var=!var! %%i
Montage !VAR! -tile 1x -geometry +0+0 "%~dpn1_m%~x1"
DEL list*.txt
I hope that helps. Sorting filenames is a common task when handing selected filenames over to the IM command line tools.
Wolfgang Hugemann

Post Reply