title: jQuery image preview exif rotation issue
body: <p>I am using this jQuery function do display the image before uploading. The images are uploaded from mobile devices and have problems with the exif orientation. This function just change the src of the preview image with the base64 code of the actual file image.</p>
  
  <p>On server side (php) i am using a function to correct the exif rotation on upload.</p>
  
  <p>Can i make something similar in jQuery to my PHP code? So that i can display the image before uploading with the right rotation?</p>
  
  <p><strong>Javascript</strong></p>
  
  <pre><code>function readURL(input) {
  
      if (input.files &amp;&amp; input.files[0]) {
          var reader = new FileReader();
  
          reader.onload = function (e) {
              $('#blah').attr('src', e.target.result);
          }
  
          reader.readAsDataURL(input.files[0]);
      }
  }
  
  $("#imgInp").change(function(){
      readURL(this);
  });
  </code></pre>
  
  <p><strong>PHP</strong></p>
  
  <pre><code>function image_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, 100);
      }
  }
  </code></pre>