【问题标题】:ImageMagick montage natural file orderImageMagick 蒙太奇自然文件顺序
【发布时间】:2016-03-11 07:12:09
【问题描述】:

我正在尝试使用 ImageMagick 蒙太奇功能来组合游戏中的大块地图。我的问题是游戏的原始文件是自然排序的

part1.png 第 2 部分.png ... part10.png

ImageMagick 会读取此内容并将 part10.png 平铺在 part1.png 之后。是否有一个标志/选项告诉 IM 按我想要的方式读取目录?这是我正在做的实时代码示例。

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

【问题讨论】:

    标签: imagemagick


    【解决方案1】:

    你可以使用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 名称不包含任何空格,则应该可以完美运行。

    【讨论】:

    • 如果是 "image-1.png" > "image-400.png" sort -V 对我有用。
    猜你喜欢
    • 1970-01-01
    • 2011-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多