Fixing Image Orientation using its Exif data

Sometimes photos are wrongly taken, eg: upside down, sideways etc, and most newbie users don't know how to rotate image, so they might just upload image "as it is". This might cause the problem later, unless you have some kind of image rotate program to set it right. Another way to fix this problem is using image EXIF data. Thankfully all new digital cameras have an orientation sensor, which sets the orientation flag in EXIF headers and can be read using PHP exif_read_data().
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
//read EXIF header from uploaded file $exif = exif_read_data($_FILES['ImageFile']['tmp_name']); //fix the Orientation if EXIF data exist if(!empty($exif['Orientation'])) { switch($exif['Orientation']) { case 8: $createdImage = imagerotate($image,90,0); break; case 3: $createdImage = imagerotate($image,180,0); break; case 6: $createdImage = imagerotate($image,-90,0); break; } }
  • Hi, I'm a begginer in PHP progamming and I'm developing a website. I'm just having the same problem with a cuple of pages. One of that page is a kind of "News page" where registered users can upload news with photos and on the other one, users with other(or same)permissions can upload second handed CNC and conventional machines for sale. I've noticed that EFIX data also contain parameters called "thumbnail". That parameters are "in the right possition" and they are very much smaller too... They are are smaller than the original image but big enougth to be uploaded to awebsite.Would you thing is It a good idea to work with the thumbnail? Otherwise, I'm trying to create my own rotate code I'm going crazy but I think copy-pasting is not the way to be a good developer. Thanks and apologies for my english... Spanish public schools... :-)
  • I am actually working on image rotate but whenever i rotate landscape image to portrait mode then it is taking some black portion in image..How we can resolve it ??
  • Thanks! I had problem with -90 angle - the picture was blurred. I solve it by using value of rotation 270 instead -90.
New question is currently disabled!