Sort alphabetically

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?".
gialandra
Posts: 11
Joined: 2019-02-10T00:32:33-07:00
Authentication code: 1152

Sort alphabetically

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Sort alphabetically

Post 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.
snibgo's IM pages: im.snibgo.com
gialandra
Posts: 11
Joined: 2019-02-10T00:32:33-07:00
Authentication code: 1152

Re: Sort alphabetically

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Sort alphabetically

Post 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.
snibgo's IM pages: im.snibgo.com
gialandra
Posts: 11
Joined: 2019-02-10T00:32:33-07:00
Authentication code: 1152

Re: Sort alphabetically

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Sort alphabetically

Post 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.
snibgo's IM pages: im.snibgo.com
gialandra
Posts: 11
Joined: 2019-02-10T00:32:33-07:00
Authentication code: 1152

Re: Sort alphabetically

Post 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!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Sort alphabetically

Post by snibgo »

I suggest you do an internet search, eg "sort numeric filenames powershell".
snibgo's IM pages: im.snibgo.com
gialandra
Posts: 11
Joined: 2019-02-10T00:32:33-07:00
Authentication code: 1152

Re: Sort alphabetically

Post 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
gialandra
Posts: 11
Joined: 2019-02-10T00:32:33-07:00
Authentication code: 1152

Re: Sort alphabetically

Post by gialandra »

I can't get a working txt file. What is the right format? Is there an example?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Sort alphabetically

Post 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
snibgo's IM pages: im.snibgo.com
gialandra
Posts: 11
Joined: 2019-02-10T00:32:33-07:00
Authentication code: 1152

Re: Sort alphabetically

Post by gialandra »

Good, but how can I tell to montage where are the images? (it lacks the folder information)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Sort alphabetically

Post 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.
snibgo's IM pages: im.snibgo.com
gialandra
Posts: 11
Joined: 2019-02-10T00:32:33-07:00
Authentication code: 1152

Re: Sort alphabetically

Post 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?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Sort alphabetically

Post 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.
snibgo's IM pages: im.snibgo.com
Post Reply