如何检测图像尺寸并对其运行命令?

Jon*_*han 4 bash scripts imagemagick

我有一个装满图像的目录,其中一些是纵向尺寸而不是横向尺寸,我想用图像编辑器打开纵向尺寸的图像。我可以运行 imagemagick 命令,identify然后得到类似something.jpg JPEG 1920x1255 1920x1255+0+0 8-bit DirectClass 159KB 0.000u 0:00.000. 我怎样才能让脚本解释这个输出,即决定哪个更大,the1920或 the 1255,然后在它上面运行命令?

Den*_*ker 9

的组合identify,并bc似乎做的伎俩:

if [ $(identify -ping -format '%W/%H>1' filename.jpg | bc -l) -eq 1 ]; then
    echo "Landscape"
else
    echo "Portrait"
fi
Run Code Online (Sandbox Code Playgroud)