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

Select file ordering under Windows

Post by whugemann »

I would like to write a Windows solution that montages, say, 4 photos in 2x2 order to an image. This is easy to achieve with montage, I know.
The difficult thing is to let the user easily choose the ordering of the images:
  • If I use Windows SendTo, I have no control on the file ordering. My experiments show that the ordering is is cyclically alphanumeric, the filename where you dragged with the mouse being the first, the order in which the files were chosen being irrelevant (?).
  • I could easily order all of the filenames alphanumerically, but this would mean that users would have to rename the filenames in order to express their wishes.
  • A possible solution would be a 2x2 ordering of drag & drop controls that transfer the filesnames to the IM batch file in the desired order. But how could that be achieved most easily?
  • Any other ideas?
I know, this question is more about programming than about IM, but as I am not sure which tool to use, I can't pose the question in one of the subforums.
Last edited by whugemann on 2019-11-11T07:10:35-07:00, edited 1 time in total.
Wolfgang Hugemann

snibgo
Posts: 12686
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Select file odering under Windows

Post by snibgo »

Yes, when I send multiple files to a BAT script, they seem to be ordered alphabetically.

There are different possible methods for users to specify the order. For example:

1. Show a list of the four files to the user. The user can slide any filename up or down the list.

2. Or: The user sends the first file to a script, then the second to the same script, then the third and the fourth. The script accumulates the file names. When it has four, it does the montage, in that order.
snibgo's IM pages: im.snibgo.com

User avatar
whugemann
Posts: 310
Joined: 2011-03-28T07:11:31-07:00
Authentication code: 8675308
Location: Münster, Germany 52°N,7.6°E

Re: Select file ordering under Windows

Post by whugemann »

1: This sounds like an idea, although "sliding" is impossible in a command box. But one could list the files with a numbering and ask the user to answer somthing like "1432".

2: You cannot really sent multiple times to the same batch script, Windows will run an new instance every time. But one could accumulate persistent information in a textfile and start the IM command only if it contains four lines (of filenames). Is that what you mean?
Wolfgang Hugemann

snibgo
Posts: 12686
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Select file ordering under Windows

Post by snibgo »

Option 1 could be done with just Windows tools. Show the current list, and prompt for the user to accept it or choose a number and whether to move it up or down. Not elegant, but possible. Or, as you say, type a new ordering such as "1432". Or a Window that allows "sliding", eg in a custom program, or perhaps some toolkit can provide this.

Yes, option 2 needs persistent information, eg in a text file, to maintain state knowledge.
snibgo's IM pages: im.snibgo.com

User avatar
whugemann
Posts: 310
Joined: 2011-03-28T07:11:31-07:00
Authentication code: 8675308
Location: Münster, Germany 52°N,7.6°E

Re: Select file ordering under Windows

Post by whugemann »

OK, here is my tested solution:

Code: Select all

SETLOCAL EnableDelayedExpansion
%~d1
CD %~p1
DEL MLIST.txt
DEL slist.txt
DEL sfl.txt
:: Query sort order
SET C=0
FOR %%i in (%*) DO (
	SET /P A=Position %%~ni%%~xi =
	ECHO !A!_%%i>>MLIST.TXT
)
::
:: Sort filenames
TYPE mlist.txt|SORT >> slist.txt
::
:: Strip off counter
FOR /F "tokens=2 delims=_" %%i IN (slist.txt) DO ECHO %%i>>sfl.txt
::
:: Search unused filename for montage
FOR /L %%i in (0,1,9) DO (
	IF NOT EXIST %~dp1\montage_%%i.jpg (
		SET FN=montage_%%i.jpg
		GOTO jump:
	)
)
:jump
:: Montage
C:\Programme\ImageMagick\Montage @sfl.txt -auto-orient -tile 2x2 -geometry 800x600+16+16 -quality 90%% !FN!
Hopefully, somebody else can draw some inspiration from it ...
Wolfgang Hugemann

Post Reply