使用 imagemagick 设置图像方向 exif 数据

Setting image orientation exif data using imagemagick

我有一组包含损坏的 exif 方向数据的图像。我想使用 imagemagick 更改这些图像的方向。我找到了以下命令 mogrify -set "%[EXIF:Orientation]" BottomRight image.jpg,但当我使用 Identify -verbose image.jpg 检查图像时它似乎不起作用,方向数据未定义。

不确定 if/how 你可以用 ImageMagick 做到这一点,但你可能想使用 exiftool 如下:

# Set orientation with exiftool
exiftool -Orientation=3 -n input.jpg
1 image files updated

# Check with **ImageMagick** 
identify -verbose input.jpg | grep rient
Orientation: BottomRight
exif:Orientation: 3

这是一个测试所有 8 个值的小循环:

for x in {1..8}; do 
   exiftool -Orientation=$x -n input.jpg > /dev/null
   identify -verbose input.jpg | grep Orientation
done

  Orientation: TopLeft
    exif:Orientation: 1
  Orientation: TopRight
    exif:Orientation: 2
  Orientation: BottomRight
    exif:Orientation: 3
  Orientation: BottomLeft
    exif:Orientation: 4
  Orientation: LeftTop
    exif:Orientation: 5
  Orientation: RightTop
    exif:Orientation: 6
  Orientation: RightBottom
    exif:Orientation: 7
  Orientation: LeftBottom
    exif:Orientation: 8

使用 ImageMagick,您可以按以下方式进行操作:

mogrify -orient <orientation> *.jpg

有效方向是

bottom-left    
right-top
bottom-right   
top-left
left-bottom    
top-right
left-top       
undefined
right-bottom 

更多信息here

您可以使用身份验证您的更改:

identify -verbose input.jpg | grep Orientation