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

Pab*_*mer 3 command-line imagemagick mogrify

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

Pab*_*mer 6

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

mogrify -orient <orientation> *.jpg

有效的方向是

bottom-left    
right-top
bottom-right   
top-left
left-bottom    
top-right
left-top       
undefined
right-bottom 
Run Code Online (Sandbox Code Playgroud)

更多信息在这里

您可以使用识别来验证您的更改:

identify -verbose input.jpg | grep Orientation


Mar*_*ell 5

不确定是否/如何使用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
Run Code Online (Sandbox Code Playgroud)

这是一个测试所有 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
Run Code Online (Sandbox Code Playgroud)