bash - imagemagick convert: how to tell if images need to be rotated? -


in rails app, let user upload images use thumbnails resources they've made. image processing imagemagick's convert command: convert jpg, letterbox 800x600px , make smaller thumbnail versions of that.

this working fine. problem images have come off iphone, example, have wrong orientation. desktop seems variously deal this: when see tiny thumbnail image in file chooser dialog, it's got wrong orientation, if open in image viewing tool, it's got correct orientation.

presumably there's header or metadata or in image file tells app needs rotate file? think need read in before other processing of image, can rotate image (if necessary) before doing other stuff.

can tell me how can this, in bash on ubuntu server?

thanks, max

edit: bit of googling suggests to exif headers...

it's true have orientation value reading exif metadata of image. using imagemagick can value

identify -format '%[exif:orientation]' <path image>  //or using identify -format '%[orientation]' <path image> 

exif orientation values range 1 8 , maps orientation below:

  • 1 = horizontal (normal)
  • 2 = mirror horizontal
  • 3 = rotate 180
  • 4 = mirror vertical
  • 5 = mirror horizontal , rotate 270 cw
  • 6 = rotate 90 cw
  • 7 = mirror horizontal , rotate 90 cw
  • 8 = rotate 270 cw

thus, image require orientation correction if metadata tag returns non 1 value. if tag returns no value can assumed having normal orientation.

to correct orientation normal can use following command

convert -auto-orient <inputimagepath> <outputimagepath>  

Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -