MyBB Community Forums

Full Version: Attachment rotating (correcting rotation)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
In mybb 1.6/8 when you upload an image taken with an android / iphone (there could be other camera's that do this too), the image is rotated incorrectly until you view the image directly. This is due to the EXIF data in the image (in JPG at least, not sure if it is for any other format) telling it to be viewed a certain way. An easy way to fix this would be to implement something like below. I will also include examples of a few images, if you click on then, they will be rotated the correct way, but on the page they are sideways.

fix_orientation($mybb->settings['uploadspath']."/".$filename);

function fix_orientation($filename) {
    $exif = exif_read_data($filename);
    if (!empty($exif['Orientation'])) {
        $image = imagecreatefromjpeg($filename);
        switch ($exif['Orientation']) {
            case 3:
                $image = imagerotate($image, 180, 0);
                break;

            case 6:
                $image = imagerotate($image, -90, 0);
                break;

            case 8:
                $image = imagerotate($image, 90, 0);
                break;
        }
        imagejpeg($image, $filename, 90);
    }
}
[attachment=34931]
[attachment=34932]
[attachment=34933]
[attachment=34934]