title: Rotating a picture in PHP once it's saved
body: <p>I have this PHP script that saves a picture on my website. I would like to, once the picture is saved, rotate the picture by 90 degrees if it's not landscape. This a piece of my script:</p>
  
  <pre><code>$uploadfile = 'path/where/to/save/picture.jpg';
  if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) { 
      //The code under here is not working
      if($_GET['landscape'] == false || $_GET['landscape'] == 'false'){
          $img = imagecreatefromjpeg($uploadfile);
          $newimg = imagerotate($img, 90.0, 0);
          imagejpeg($newimg, $uploadfile);
      }
  
      //this is code under here is working
      $prev = create_preview($filename, $uploadfile, $ext, true);
  }
  </code></pre>
  
  <p>As you can see I move_uploaded_file() and then I have an if statement that if the picture is not landscape (so landscape == false) I rotate it. Then I create a preview of the picture.</p>
  
  <p>If I comment out the if statement that checks the landscape the code WORKS, so it uploads the picture but it's NOT ROTATED as I want and creates a preview. If I let the if uncommented (like in this case) it seems like it's not saved anymore because when I try to visualize it I see nothing. This means that the code flow goes into the if, then something happens and the picture is not visualized anymore. The problem is in the if statement that rotates the picture.</p>
  
  <p>So there is definitely something wrong in the procedure to rotate the picture, but I don't understand exactly what's wrong, I create the image from the location it has been uploaded to, I rotate it using the PHP function and then recreate the image in the same exact location.</p>
  
  <p>Can anyone of you see where I'm getting this wrong?</p>
  
  <p>Thanks,</p>
  
  <p>Masiar</p>