Posted By

hgc81538 on 08/22/14


Tagged

php image jpg exif iphone orientation android


Versions (?)

fix orientation of jpg image for iphone & android in php


 / Published in: PHP
 

  1. function image_fix_orientation($path){
  2. $image = imagecreatefromjpeg($path);
  3. $exif = exif_read_data($path);
  4.  
  5. if (!empty($exif['Orientation'])) {
  6. switch ($exif['Orientation']) {
  7. case 3:
  8. $image = imagerotate($image, 180, 0);
  9. break;
  10. case 6:
  11. $image = imagerotate($image, -90, 0);
  12. break;
  13. case 8:
  14. $image = imagerotate($image, 90, 0);
  15. break;
  16. }
  17. imagejpeg($image, $path);
  18. }
  19. }
  20.  
  21. // For JPEG image only
  22. image_fix_orientation('/path/to/image.jpg');

Report this snippet  

You need to login to post a comment.