Auto Image Rotate for iPhone and iPad [Deleted]

AndyB

Well-known member
AndyB submitted a new resource:

Auto Image Orientation for iPhone and iPad - Uploaded images from iPhone and iPad will auto orient

This hack will fix the problem when images uploaded from an iPhone or iPad end up in the wrong orientation (sideways).

You must have ImageMagick installed.

Code:
library/Xenforo/Upload.php

Line #189

Add hack to auto orient iPhone and iPad images.

$imageInfo = @getimagesize($this->_tempFile);
if (!$imageInfo)
{
    return;
}

// start hack	

exec("/usr/bin/mogrify -auto-orient $this->_tempFile");

// end hack

Read more about this resource...
 
where can i find ImageMagick?

Ask your web hosting provider to install it on your server. Then enable it in the Admin CP.

Admin CP -> Home -> Options -> Attachments -> Default Image Processor -> ImageMagick PECL Extension
 
May be you should add in the addon presentation that the exec command is probably disabled on most of share hosting plans.
 
  • Like
Reactions: HWS
Also, some better detailed instructions on what to do with that code. Since its all inside the box, some people might not know where or what to copy/paste.
 
I contacted my web host which is ipage and they said they will not install it is their another way so i can use this add-on?
 
This hack probably needs modification to work in XF 1.2, as the line number now puts it in the middle of an existing function. (I can probably guess where it might go.)
 
OK, just eyeballing things here, this is where the hack must go in XF 1.2, inserting it around line 204.

Code:
        $imageInfo = @getimagesize($this->_tempFile);
        if (!$imageInfo)
        {
            if (in_array($this->_extension, array('gif', 'jpg', 'jpe', 'jpeg', 'png')))
            {
                $this->_errors['extension'] = new XenForo_Phrase('the_uploaded_file_was_not_an_image_as_expected');
            }
            return;
        }

// START HACK
exec("/usr/bin/mogrify -auto-orient $this->_tempFile");
// END HACK

        $imageInfo['width'] = $imageInfo[0];
        $imageInfo['height'] = $imageInfo[1];
        $imageInfo['type'] = $imageInfo[2];

Untested!
 
For Xenforo version 1.2.

File: library/Xenforo/Upload.php

At line #195

Code:
		$imageInfo = @getimagesize($this->_tempFile);
		if (!$imageInfo)
		{
			if (in_array($this->_extension, array('gif', 'jpg', 'jpe', 'jpeg', 'png')))
			{
				$this->_errors['extension'] = new XenForo_Phrase('the_uploaded_file_was_not_an_image_as_expected');
			}
			return;
		}
		
		// start hack	
		
		exec("/usr/bin/mogrify -auto-orient $this->_tempFile");
		
		// end hack
 
Provided this works on my server, what I might do is write that line as "@exec("/usr/bin.....etc. " so it kills any error message if it fails.
 
  • Like
Reactions: HWS
Top Bottom