Check orientation of uploaded image and rotate.

This modification will check orientation of uploaded images and if necessary will rotate.

Note: At the moment, this modification only works if GD is installed and enabled. Most hosting has the GD library installed so this should not be a problem for most sites.


Edit modules\boonex\photos\classes\BxPhotosUploader.php

Look for this at about line 368

                switch($aSize[2]) {
                    case IMAGETYPE_JPEG: $sExtension = '.jpg'; break;
                    case IMAGETYPE_GIF:  $sExtension = '.gif'; break;
                    case IMAGETYPE_PNG:  $sExtension = '.png'; break;
                    default:
                        @unlink($sTempFileName);
                        return false;
                }


Insert this just under it.

// Deano. check orientation start
                $bUseGD = getParam('enable_gd') == 'on' && extension_loaded('gd') ? true : false;
                if($bUseGD) {
                    $exif = exif_read_data($sTempFileName);
                    if (!empty($exif['Orientation'])) {
                        if($exif['Orientation'] == 3 || $exif['Orientation'] == 6 || $exif['Orientation'] == 8) {
                            switch($aSize[2]) {
                                case IMAGETYPE_JPEG: $source = imagecreatefromjpeg($sTempFileName); break;
                                case IMAGETYPE_GIF:  $source = imagecreatefromgif($sTempFileName); break;
                                case IMAGETYPE_PNG:  $source = imagecreatefrompng($sTempFileName); break;
                            }
                            switch ($exif['Orientation']) {
                                case 3: $source = imagerotate($source, 180, 0); break;
                                case 6: $source = imagerotate($source, -90, 0); break;
                                case 8: $source = imagerotate($source, 90, 0); break;
                            }
                            switch($aSize[2]) {
                                case IMAGETYPE_JPEG: imagejpeg($source, $sTempFileName); break;
                                case IMAGETYPE_GIF:  imagegif($source, $sTempFileName); break;
                                case IMAGETYPE_PNG:  imagepng($source, $sTempFileName); break;
                            }
                            $aSize = getimagesize($sTempFileName);
                        }
                    }
                }
// Deano. check orientation end



Tested with images that were taken and uploaded using my iPhone 5

https://www.deanbassett.com
Quote · 29 May 2014

Thanks for this free patch Deano; your work is appreciated.  I think I will contact the site owner where I installed the photo editor module and see if they want it applied to their site.  Of course a manual way of rotating the images is still needed in case the EXIF of the device does not include orientation.  Many devices do but some may be using devices that do not.

Geeks, making the world a better place
Quote · 29 May 2014

Thanks!

Will test this out.

Been getting numerous "sideways" photos from new members.

Quote · 29 May 2014

Hey Deano, do you want to tackle the sideways video issue?  ffmpeg has a switch for rotating videos; if we can check the video orientation and then set the ffmpeg swtich to rotate the video during processing, then we have both covered :-).

Geeks, making the world a better place
Quote · 29 May 2014

 

This modification will check orientation of uploaded images and if necessary will rotate.

Deano92964,

thank you for this. But if you upload a image thru default dolphin mobile app on samsung it turns it up side down!
on Photos mod or Evo Wall add photo... both the same result.
So i think there is still a lil tweaking to do.

If I upload thru responsive website it works fine on my samsung.

Quote · 30 May 2014

Does not happen with my iphone.

I may have to have you send me some photos taken both portrait and in landscape from your phone so i can extract and analyze the exif data.

From what i can find online, some models of Samsung phones are setting that data incorrectly.

https://www.deanbassett.com
Quote · 30 May 2014

 

From what i can find online, some models of Samsung phones are setting that data incorrectly.

If that is the case, then it would mean we would have to have a way of knowing the device.  I know that EXIF usually lists the device for cameras; would that be the same for phones?

Geeks, making the world a better place
Quote · 30 May 2014

 

 

From what i can find online, some models of Samsung phones are setting that data incorrectly.

If that is the case, then it would mean we would have to have a way of knowing the device.  I know that EXIF usually lists the device for cameras; would that be the same for phones?

 Yes. The phone information should be there.

https://www.deanbassett.com
Quote · 30 May 2014

ok question: why does it happen when i use mobile app but when i use responsive site upload it works fine.

it uses the same photo and details from phone... so i would think that the code that is used on mobile app page is doing something...

 

switch ($exif['Orientation']) {
                                case 3: $source = imagerotate($source, 180, 0); break; changed to -180

that fixed the rotate issue on the samsung for me.

Oops talked to soon. same issue when using mobile app. but good now when responsive site upload.
                          

Quote · 30 May 2014

 

but good now when responsive site upload.

You said it was good on responsive before as well.

180 vs -180 are both the same. One rotates clock wise the other counter clock wise. But the result would be the same.


https://www.deanbassett.com
Quote · 30 May 2014

 

180 vs -180 are both the same

you would think that right.... but on samsung i guess not. I will test it on Iphone5 later tonight.
Yes i tested it thru my site that is responsive and that works now on mobile the correct way like you are on laptop/tablet/desktop. But with dolphin mobile app it still is up side down. So you would think that there is a bit of code that screws up there..

is this happening with all people who use mobile device i wonder?

Quote · 30 May 2014

 

 

180 vs -180 are both the same

you would think that right.... but on samsung i guess not. I will test it on Iphone5 later tonight.
Yes i tested it thru my site that is responsive and that works now on mobile the correct way like you are on laptop/tablet/desktop. But with dolphin mobile app it still is up side down. So you would think that there is a bit of code that screws up there..

is this happening with all people who use mobile device i wonder?

 
Well not on my site. I tested my iphone 5 on both the normal site with desktop browser and with the mobile app and did not have a problem.

https://www.deanbassett.com
Quote · 30 May 2014

I would still like to see photos so i can check out the exif info. What i did for testing was tape a piece of paper to the wall with top, bottom, left and right written on the paper at the proper locations.

Then take 4 photos.

Photo 1 taken with top of the phone up.

Photo 2 taken with the top of the phone pointing left.

Photo 3 taken with the top of the phone pointing down.

Photo 4 taken with the top of the phone pointing right.

PM me and i'll provide email address to send the photos to.

https://www.deanbassett.com
Quote · 30 May 2014

One thing i did notice. On my iPhone 5c it does not matter which direction the phone was in when the photo was taken. When viewed on the phone it was always right side up. And when uploaded with the mobile app directly from the phone, all of them are normal.

For me the photos orientation is wrong only when i download them from the phone to my pc. Then upload using the desktop browser.

When uploaded with the app directly from the iphone, the exif data is different and the orientation is always 1 so my code is not even run under that condition. When uploading directly from my phone using the mobile app, the Make, Model, GPS and other info is removed from the exif data.

https://www.deanbassett.com
Quote · 30 May 2014

Hi 

 

Will this work in 7.2? 

Thanks

 

Stan

Quote · 3 Oct 2015

 

Hi 

 

Will this work in 7.2? 

Thanks

 

Stan

 It isn't necessary in 7.2  The new HTML5 uploader in 7.2 auto-orients the image in-browser before upload.... at least that's what AlexT said here: http://www.boonex.com/n/new-photo-uploader-in-dolphin-7-2#44556

My opinions expressed on this site, in no way represent those of Boonex or Boonex employees.
Quote · 4 Oct 2015

I often had this problem before, but since 7.2 I have never had this problem, it seems that 7.2 addresses this problem effectively in practice.

Baloo
Quote · 4 Oct 2015

Doesn't seem like I can modify the ones that were put up sideways BEFORE 7.2.

 

Is there a way?

Quote · 5 Oct 2015

still getting the sideways problem in 7.2.1

Quote · 28 Nov 2015
 
 
Below is the legacy version of the Boonex site, maintained for Dolphin.Pro 7.x support.
The new Dolphin solution is powered by UNA Community Management System.