0

I am building a classifieds site on WordPress where users can upload their ads/images from front-end. However, when horizontal pictures are uploaded, they upload as vertical.

I looked into the issue and found the following suggested solution for fixing image orientation using its Exif data:

//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;
}
}

I placed this in my WP theme's functions.php file but this did not solve my issue. Unfortunately I don't have enough code knowledge at all to figure out what is wrong with this. I would really appreciate any advice/input.

3
  • All of the pictures? Some of the pictures? Could you provide an example of image that uploads wrong?
    – Rarst
    Oct 18 '15 at 10:40
  • 1
    Rarst, thank you for your response. All of my horizontal pictures (taken on my Android phone) were showing up vertical. However, I was able to solve this problem by installing plugin "Image Rotation Repair". (The "Image Rotation Fixer" plugin did not work for me.) Thank you for your support! Oct 18 '15 at 12:44
  • 1
    You should add that as an answer so that others can benefit from it. :) Maybe with a bit of detail on what plugin is doing to address the issue.
    – Rarst
    Oct 18 '15 at 12:46
1

summersummer solved the problem reported by installing the Image Rotation Repair, which describes itself as follows:

The Image Rotation Repair plugin simply fixes image orientation based on EXIF data. This is primarily a patch for mis-oriented images delivered from iPhones. Functionally it filters all uploads and if EXIF->Orientation is set to a number greater than 1, then the image is resaved with a new orientation before the image is processed by WordPress.

2
  • 1
    Also worth noting is that there is a trac ticket about that which is aimed to be solved at 4.8 Feb 12 '17 at 4:17
  • Excellent! Looks like it's #37140 Feb 12 '17 at 7:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.