使用bash将所有图像设置为横向
在文件资源管理器或shotwell中,有些图像显示为纵向模式,有些图像显示为横向模式。 但是使用bash将所有图像设置为横向,bash,imagemagick,identify,Bash,Imagemagick,Identify,在文件资源管理器或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 我使用以下脚本获
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
#/bin/bash
对于*.JPG中的img;做
标识=$(标识“$img”)
[[$identify=~([0-9]+)x([0-9]+)]||\
{echo无法获取大小>&2;continue;}
宽度=${BASH_重新匹配[1]}
高度=${BASH_重赛[2]}
让好的宽度=高度+高度/2
方向=$(标识-格式“%[exif:orientation]”$img)
如果((方向>1));然后水平裁剪
echo“$img是肖像”
name=“temp”
转换-旋转90“$img”“$name”
mv“$img”肖像画
mv“$name”“$img”
fi
如果((宽度<良好宽度));然后水平裁剪
让新高度=宽度*2/3
新宽度=$width
让顶部='(高度-新高度)/2'
左=0
elif((宽度!=好的宽度));然后垂直裁剪
让新的宽度=高度*3/2
新高度=$height
让左='(宽度-新宽度)/2'
top=0
fi
转换-自动定向“$img”-裁剪“$new_width”x$new_height+$left+$top-调整120x80拇指大小-“$img”
完成
您可以将-auto-oriented
选项添加到convert
以自动旋转图像
如果您只需要获得方向,则必须在标识上使用格式说明符,例如:
identify -format '%[exif:orientation]' image_file.jpg
有关更多详细信息,请参阅ImageMagick文档中的部分。使用转换工具尝试-orient
和-auto-orient
标志