
假設有 50 張圖像,我想知道哪一張的寬度最大。我應該使用哪些指令?
答案1
此命令(從 ImageMagick 識別)輸出最大寬度的圖像:
identify -format "%w %h %f\n" *.png | sort -n -r -k 1 | head -n 1
-format "%w %h %f = 寬度、高度、檔名
結果:wh image.png
來源:在資料夾中尋找最大影像尺寸: https://unix.stackexchange.com/questions/155544/find-largest-image-dimensions-in-folder
如果您的映像不在同一資料夾中,請開啟終端並從包含子目錄的資料夾執行此腳本。
find . -iname "*.png" -type f -exec identify -format "%w %h %f\n" '{}' \; | sort -n -r -k 1 | head -n 1
注意:如果您有多個具有相同寬度的圖像,它將只顯示一個結果。若要獲得按寬度排序的所有圖像的列表,請從前面的命令中刪除 head -n 1。
答案2
該命令將在目前目錄中搜尋圖像寬度。
在安裝 imageinfo 之前:
sudo apt install imageinfo
然後輸入這個命令
find . -maxdepth 1 -type f -iregex ".*/.*\.\(jpg\|jpeg\|png\|tiff\|bmp\svg\)" \
-exec bash -c "echo -ne {}' '; imageinfo --width {}; echo " \;\
| sort -k2 -n
如果您只想要最大的一個,請在上面的命令中添加一個管道
... | tail -n 1