簡體   English   中英

ImageMagick蒙太奇自然文件順序

[英]ImageMagick montage natural file order

我正在嘗試使用ImageMagick蒙太奇功能來組合游戲中的大塊地圖。 我的問題是,游戲的原始文件自然會像

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

ImageMagick讀取此內容,並將在part1.png之后平鋪part10.png。 是否有標記/選項告訴IM以我想要的方式讀取目錄? 這是我正在做的實時代碼示例。

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

您可能可以使用sort -g (這是常規的數字sort )來獲取所需的內容。

測試:

創建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名稱不包含任何空格,則應該可以正常使用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM