1

I am trying to use the ImageMagick montage feature to combine chunks of maps from a game. My issue is that the game's original files are naturally ordered like

part1.png part2.png ... part10.png

ImageMagick reads this and will tile part10.png after part1.png. Is there a flag/option to tell IM to read the directory the way I want it to? This is a live code sample of what I'm doing.

montage                    \
    -alpha on              \
    -background none       \
    -mode concatenate      \
    -tile x{$grid}         \
    -mattecolor none       \
    {$input_dir}/*.png     \
    {$output_file}
4

1 回答 1

2

您可以使用sort -g(这是一般的数字排序)来获得您想要的。

测试:

创建 12 个虚拟文件:

for i in {1.12} ; do touch ${i}.txt ; done

列出文件:

ls -1 *.txt
  1.txt
  10.txt
  11.txt
  12.txt
  2.txt
  3.txt
  4.txt
  5.txt
  6.txt
  7.txt
  8.txt
  9.txt

用于sort -g以不同的顺序列出它们:

ls -1 *.txt | sort -g
  1.txt
  2.txt
  3.txt
  4.txt
  5.txt
  6.txt
  7.txt
  8.txt
  9.txt
  10.txt
  11.txt
  12.txt

现实生活:

现在应用它来解决您的问题:

montage                                    \
    -alpha on                              \
    -background none                       \
    -mode concatenate                      \
    -tile x{$grid}                         \
    -mattecolor none                       \
     $(ls -1 {$input_dir}/*.png | sort -g) \
     {$output_file}

如果你的$input_dir名字不包含任何空格,这应该可以完美地工作。

于 2014-01-13T16:11:37.510 回答