我在试着把我的照片分成肖像和风景。我想出了一个打印jpeg大小尺寸的命令:
identify -format '%w %h\n' 1234.jpg
1067 1600如果我在bash脚本中使用它将所有的风景图片移到另一个文件夹中,我希望它是这样的
#!/bin/bash
# loop through file (this is psuedo code!!)
for f in ~/pictures/
do
# Get the dimensions (this is the bit I have an issue with)
identify -format '%w %h\n' $f | awk # how do I get the width and height?
if $width > $hieght
mv ~/pictures/$f ~/pictures/landscape/$f
fi
done我一直在看awk手册页,但我似乎找不到语法。
发布于 2012-04-17 16:32:16
你不需要AWK。这样做:
identify -format '%w %h\n' $f | while read width height
do
if [[ $width -gt $height ]]
then
mv ~/pictures/$f ~/pictures/landscape/$f
fi
done发布于 2012-04-17 16:27:02
您可以使用array
# WxH is a array which contains (W, H)
WxH=($(identify -format '%w %h\n' $f))
width=${WxH[0]}
height=${WxH[1]}发布于 2012-04-17 16:27:12
format=`identify -format '%w %h\n' $f`;
height=`echo $format | awk '{print $1}'`;
width=`echo $format | awk '{print $2}'`;https://stackoverflow.com/questions/10187617
复制相似问题