在文件浏览器或Shotwell中,一些图像显示为纵向模式,而另一些则显示为横向模式。但是,
横向:
我使用以下脚本来获取我的图片的宽度和高度: 批量裁剪和调整大小以创建缩略图 有没有办法也获得方向?
------------------------------------------------------------------------------------------
我想要批量裁剪和调整大小以创建缩略图(解决方案),如果我在池中得到一些纵向图像,它会将它们旋转。
完整解决方案:
identify
命令无法区分它们:横向:
IMG_0064.JPG JPEG 3648x2736 3648x2736+0+0 8-bit DirectClass 3.319MB 0.000u 0:00.000
肖像:
IMG_0108.JPG JPEG 3648x2736 3648x2736+0+0 8-bit DirectClass 3.004MB 0.000u 0:00.000
我使用以下脚本来获取我的图片的宽度和高度: 批量裁剪和调整大小以创建缩略图 有没有办法也获得方向?
------------------------------------------------------------------------------------------
我想要批量裁剪和调整大小以创建缩略图(解决方案),如果我在池中得到一些纵向图像,它会将它们旋转。
完整解决方案:
#! /bin/bash
for img in *.JPG ; do
identify=$(identify "$img")
[[ $identify =~ ([0-9]+)x([0-9]+) ]] || \
{ echo Cannot get size >&2 ; continue ; }
width=${BASH_REMATCH[1]}
height=${BASH_REMATCH[2]}
let good_width=height+height/2
orientation=$(identify -format '%[exif:orientation]' $img)
if (( orientation > 1 )) ; then # crop horizontally
echo "$img is portrait"
name="temp"
convert -rotate 90 "$img" "$name"
mv "$img" "portrait_$img"
mv "$name" "$img"
fi
if (( width < good_width )) ; then # crop horizontally
let new_height=width*2/3
new_width=$width
let top='(height-new_height)/2'
left=0
elif (( width != good_width )) ; then # crop vertically
let new_width=height*3/2
new_height=$height
let left='(width-new_width)/2'
top=0
fi
convert -auto-orient "$img" -crop "$new_width"x$new_height+$left+$top -resize 120x80 thumb-"$img"
done