title: TinyMCE display image with erong width and height after PHP rotation
body: <p>This PHP script is handling upload and working with TinyMCE Editor. There is a problem though if an image has EXIF orientation meta data.The image rotated correctly but TinyMCE display the image with the wronf width and height. I need to pass the new width and height to TinyMCE but not sure how to do it?</p>
  <pre><code>&lt;?php
  //error_reporting(0);
  //Only these origins are allowed to upload images *
      $accepted_origins = array(&quot;http://localhost&quot;, &quot;http://127.0.0.1&quot;, &quot;http://192.168.1.1&quot;, &quot;http://example.com&quot;);
  
      // Set the destination folder for image
      $month = strtolower(date('M'));
      $year = date('Y');
      $newspath = &quot;img/news/&quot;;
  
      if (!is_dir(&quot;$newspath/$year/$month&quot;)) {
      mkdir(&quot;$newspath/$year/$month&quot;, 0777, true);
  }
      $imageFolder = &quot;$newspath/$year/$month/&quot;;
  
      reset ($_FILES);
      $temp = current($_FILES);
      if (is_uploaded_file($temp['tmp_name'])){
          if (isset($_SERVER['HTTP_ORIGIN'])) {
              // same-origin requests won't set an origin. If the origin is set, it must be valid.
              if (in_array($_SERVER['HTTP_ORIGIN'], $accepted_origins)) {
                  header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
              } else {
                  header(&quot;HTTP/1.1 403 Origin Denied&quot;);
                  return;
              }
          }
  
          /*
              If your script needs to receive cookies, set images_upload_credentials : true in
              the configuration and enable the following two headers.
          */
          // header('Access-Control-Allow-Credentials: true');
          // header('P3P: CP=&quot;There is no P3P policy.&quot;');
  
          // Rewrite bad filenames
          $temp['name'] = preg_replace(array('/\s+/', '/[^a-zA-Z0-9\-\._]/', '/\.(?=.*\.)/', '/[\-]+/', '/[_]+/'), array('_', '', '_', '_', '_'), strtolower($temp['name']));
  
          // Verify extension
          if (!in_array(strtolower(pathinfo($temp['name'], PATHINFO_EXTENSION)), array(&quot;gif&quot;, &quot;jpg&quot;, &quot;jpeg&quot;, &quot;png&quot;))) {
  
                  header(&quot;HTTP/1.1 400 Invalid extension.&quot;);
                  return;
          }
  
          // Accept upload if there was no origin, or if it is an accepted origin
          $tempname = $temp['name'];
          $filetowrite = $imageFolder . $tempname;
          $randompin = mt_rand(1000, 9999);
          // If file name already exists rename
          if (file_exists($filetowrite)) {
          $tempname =  $randompin . $tempname;
          $filetowrite = $imageFolder . $tempname;
          }
  
          // If EXIF Orientation data exists, rotate image as required
          $savetmpname = $temp['tmp_name'];
          function correctImageOrientation($savetmpname) {
              if (function_exists('exif_read_data')) {
                  $exif = exif_read_data($savetmpname);
                  if($exif &amp;&amp; isset($exif['Orientation'])) {
                      $orientation = $exif['Orientation'];
                      if($orientation != 1){
                          $img = imagecreatefromjpeg($savetmpname);
                          $deg = 0;
                          switch ($orientation) {
                              case 3:
                                  $deg = 180;
                                  break;
                              case 6:
                                  $deg = 270;
                                  break;
                              case 8:
                                  $deg = 90;
                                  break;
                          }
                          if ($deg) {
                              $img = imagerotate($img, $deg, 0);       
                          }
                          //Rewrite rotated image back to the disk
                          imagejpeg($img, $savetmpname, 75);
                      } // if there is some rotation necessary
                  } // if have the exif orientation info
              } // if function exists     
          }
          // Move uploaded files and rotate if requireD
          move_uploaded_file($savetmpname, $filetowrite);
          correctImageOrientation($filetowrite);
          //}
          // Respond to the successful upload with JSON.
          // Use a location key to specify the path to the saved image resource.
          // { location : '/your/uploaded/image/file'}
          // echo json_encode(array('location' =&gt; $filetowrite));
  
          $passpath = $year.'/'.$month.'/'.$tempname;
  
          echo json_encode(array('location' =&gt; $passpath));
      } else {
          // Notify editor that the upload failed
          header(&quot;HTTP/1.1 500 Server Error&quot;);
      }
  ?&gt;
  
  </code></pre>