1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Auto Image Rotate for iPhone and iPad

Discussion in 'XenForo Development Discussions' started by AndyB, Oct 26, 2013.

  1. AndyB

    AndyB Well-Known Member

    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.

    The code snippet below is for Xenforo v1.2.x.

    library/Xenforo/Upload.php

    Line #184

    PHP:
    protected function _checkImageState()
    {
        
        
    // start hack    
        
        
    exec("/usr/bin/mogrify -auto-orient $this->_tempFile");
        
        
    // end hack        

     
    Last edited: Oct 26, 2013
    seojoseph, Rudy and Mouth like this.
  2. Mouth

    Mouth Well-Known Member

    Should be in core!
     
  3. Rudy

    Rudy Well-Known Member

    We have it installed, but I don't know if it is going to run without root or superuser permissions. At least in our server setup, I'm almost sure we can't run "system" commands. Will this throw an error somewhere if I try it out and it fails?

    Pretty sad we have to do a sloppy workaround due to the failure of these devices to upload properly, though.
     
  4. AndyB

    AndyB Well-Known Member

    I suggest first taking a picture with your iPhone or iPad and verifying the attachment is sideways. Once you figure out which way holding the iPhone or iPad creates a sidways image you can add the code and duplicate the test. This will verify if the hack is working.
     
  5. Rudy

    Rudy Well-Known Member

    No apple products here (my choice) ;) . I am more concerned if the code will actually work on the server or if not, whether or not it will throw an error message. I may have a few minutes today to give it a try and be the guinea pig in all this. :D

    Should be, but there may be a reason that it can't. XF would make the assumption that the server has ImageMagick installed. One workaround might be to specifically state that IM is installed in the board options, or have XF detect it.
     
  6. AndyB

    AndyB Well-Known Member

    If you would like me to test it for you using my iPhone and iPad, I can do that for you. Provide a test login information via Private Conversation.
     
  7. Rudy

    Rudy Well-Known Member

    Thanks for the offer! Once I get around to doing this, I'll drop you a note. I'm working on a stack of assignments for one of my courses right now...
     
  8. Rambro

    Rambro Well-Known Member

    @AndyB I can not for the life of me to seem to get this to work. I tried modding the file two different times and the photo's still upload rotated. I have imagick installed
     
  9. AndyB

    AndyB Well-Known Member

    Please verify you have this setting enabled:

    Admin CP -> Options -> Attachments

    pic001.jpg
     
    Last edited: Nov 2, 2013
  10. Rambro

    Rambro Well-Known Member

    Yep. You got PM.
     
  11. tommydamic68

    tommydamic68 Well-Known Member

    is this for 1.2.3?

    have it on 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
     
  12. AndyB

    AndyB Well-Known Member

    I don't have XenForo v1.2.3 downloaded yet, so can can't tell you the exact line. But put the code directly under the function.

    PHP:
        /**
         * Checks the state of the upload to determine if it's
         * a valid image.
         */
        
    protected function _checkImageState()
        {
            
            
    // start hack    
            
            
    exec("/usr/bin/mogrify -auto-orient $this->_tempFile");
            
            
    // end hack    
     
  13. tommydamic68

    tommydamic68 Well-Known Member

    Just an FYI - but I had it as this code states and it worked, not sure why it changed its location from line 195 to your most recent post.
     
  14. AndyB

    AndyB Well-Known Member

    Glad to hear it's working for you, Tommy.

    Yes either location for the code addition is fine, it's just easier to describe inserting it where I now show.
     
    Last edited: Nov 12, 2013
    tommydamic68 likes this.
  15. tommydamic68

    tommydamic68 Well-Known Member

    It's the second time I had to update this hack in the PHP file due to 2 Xenforo update releases. Which overwrite your code. Would be nice if it could be an add on. ;)
     
  16. xf_phantom

    xf_phantom Well-Known Member

    tommydamic68 likes this.
  17. AndyB

    AndyB Well-Known Member

    We tried to make this an add-on, but unfortunately not all XenForo code can be extended so an add-on can be created.
     
  18. John007

    John007 Active Member

    this should be core a long time ago! my forum is based on photo uploads and 7,000 visitors per day are using iphones/ipads

    whats up K&M? :)
     
  19. AndyB

    AndyB Well-Known Member

    If you are having problems with this not working on your server, please make sure you have access to the following file:

    PHP:
    /usr/bin/mogrify
     
  20. tommydamic68

    tommydamic68 Well-Known Member

    It would make sense for Xenforo to have this code standard...
     

Share This Page