Page 1 of 2

Sort alphabetically

Posted: 2019-02-12T04:47:25-07:00
by gialandra
I have a lot of images named like these below but I can find the syntax to pass this sorting (name) to montage and the results is not correct. Is it possible to find a way to pass the montage the right sorting?

0x0x0.png
0x0x1.png
0x0x2.png
0x0x3.png
0x0x4.png
0x0x5.png
0x0x6.png
0x0x7.png
0x0x8.png
0x0x9.png
0x0x10.png
0x0x11.png
0x1x0.png
0x1x1.png

Re: Sort alphabetically

Posted: 2019-02-12T05:20:01-07:00
by snibgo
You can list the files in the command line. Or put the names in a text file, one image file per line, and use that filename prefixed with @ in the command line.

More generally, when creating a series of numbered images I suggest you use leading zeroes.

Re: Sort alphabetically

Posted: 2019-02-12T06:09:17-07:00
by gialandra
I have tried to list with Dir command but unsuccessfully. It seems that something other is needed, but it is out of my capabilities

Re: Sort alphabetically

Posted: 2019-02-12T06:30:18-07:00
by snibgo
You can rename the files with leading zeroes, so they are:

0x0x00.png
0x0x01.png
0x0x02.png
0x0x03.png
0x0x04.png
0x0x05.png
0x0x06.png
0x0x07.png
0x0x08.png
0x0x09.png
0x0x10.png
0x0x11.png
0x1x00.png
0x1x01.png

An alphabetical sort will then do what you want.

Re: Sort alphabetically

Posted: 2019-02-12T06:42:34-07:00
by gialandra
In this discussion I have reported few files, in reality they are several hundreds. It needs an automated way to rename the last digits and the middle digits.

Re: Sort alphabetically

Posted: 2019-02-12T06:51:38-07:00
by snibgo
You could do it in a script. For each filename, break it up into fields. Add leading zeros as needed, and combine the fields to make a new name.

Re: Sort alphabetically

Posted: 2019-02-12T06:56:22-07:00
by gialandra
Thanks for suggestion but, again, it is out of my capabilities. I'm searching for a suggestion on the web to get a txt with right order, maybe a powershell command ... thank you for you help!

Re: Sort alphabetically

Posted: 2019-02-12T07:24:45-07:00
by snibgo
I suggest you do an internet search, eg "sort numeric filenames powershell".

Re: Sort alphabetically

Posted: 2019-02-12T13:42:44-07:00
by gialandra
I found the poweshell code that list the files correctly:

Get-ChildItem -path C:\INPUTFOLDER\*.png | Sort-Object { [regex]::Replace($_.Name, '\d+', { $args[0].Value.PadLeft(20) }) } > C:\OUTFOLDER\file.txt

Now I have to searching for the way to get a txt that Montage can crunch

Re: Sort alphabetically

Posted: 2019-02-14T02:17:35-07:00
by gialandra
I can't get a working txt file. What is the right format? Is there an example?

Re: Sort alphabetically

Posted: 2019-02-14T06:47:09-07:00
by snibgo
To use montage with a text file of filenames, create a text file called for example "myimages.txt", like this:

Code: Select all

0x0x0.png
0x0x1.png
0x0x2.png
... and so on. Then the montage command could be:

Code: Select all

magick montage @myimages.txt out.png

Re: Sort alphabetically

Posted: 2019-02-14T08:55:05-07:00
by gialandra
Good, but how can I tell to montage where are the images? (it lacks the folder information)

Re: Sort alphabetically

Posted: 2019-02-14T09:23:38-07:00
by snibgo
I don't understand your question.

If the files 0x0x0.png and so on are not in the current directory (aka folder), you need to prefix the names with their directory, in the usual way for your platform.

Re: Sort alphabetically

Posted: 2019-02-14T09:51:42-07:00
by gialandra
Let me know if you see something wrong:

1. with powershell command I create the file: C:\1\myimages.txt. Inside I see:

C:\1\PNG\2x0x0.png
C:\1\PNG\2x0x1.png
C:\1\PNG\2x0x2.png
...

2. I open Command prompt and:

Microsoft Windows [Versione 10.0.17763.316]
(c) 2018 Microsoft Corporation. Tutti i diritti sono riservati.

C:\1>magick montage -tile 7x -geometry +0+0 @myimages.txt "C:\1\col.png"
montage: unable to open image 'ÿþC': No such file or directory @ error/blob.c/OpenBlob/3485.
montage: no decode delegate for this image format `' @ error/constitute.c/ReadImage/556.
montage: `C:\1\col.png' @ error/montage.c/MontageImageCommand/1777.

With the command below montage produces regulary the col.png file

C:\1>magick montage -tile 7x -geometry +0+0 C:\1\PNG\*.png "C:\1\col.png"
C:\1>

What is the problem for you?

Re: Sort alphabetically

Posted: 2019-02-14T11:20:51-07:00
by snibgo
gialandra wrote:montage: unable to open image 'ÿþC': No such file or directory
I suspect your file "myimages.txt" contains some junk, perhaps a UTF-8 byte order mark ("BOM").

If you upload myimages.txt to somewhere and paste a link to it, I can take a look.