PHP: Rotate an image as its created
<p>Today I am having this small issue with my cart script again. When i upload from my desktop my images are orientated the way you want them by default so as I upload them, they load properly. But when I post items from my phone, the images are loaded sideways!</p>

<p>I CANT get the orientation through exif because of my server (don't have root access to fix that) so I was just going to see if the width is less then the height, then rotate them, but the code isn't working properly.</p>

<p>Right now the script uploads a file temporarily, then runs two functions to make a PNG version of the image for a thumbnail and a full sized version  in the proper folders. It works to make the images just fine, the problem being it doesn't rotate them before it saves them if they need to be rotated. I have included my current function to create the images, what am i doing wrong that they aren't being rotated?</p>

<pre><code>function createFullImage($filepath, $uploadpath) {
    list($width, $height, $original_type) = getimagesize($filepath);
    if($original_type === 1) {
        $imgt = "ImageGIF";
        $imgcreatefrom = "ImageCreateFromGIF";
    } elseif ($original_type === 2) {
        $imgt = "ImageJPEG";
        $imgcreatefrom = "ImageCreateFromJPEG";
    } elseif ($original_type === 3) {
        $imgt = "ImagePNG";
        $imgcreatefrom = "ImageCreateFromPNG";
    } else {
        return false;
    }
    $old_image = $imgcreatefrom($filepath);
    $new_image = imagecreatetruecolor($width, $height); // create new image
    imagecopyresampled($new_image, $old_image, 0, 0, 0, 0, $width, $height, $width, $height);
    if(height &gt; width) {
        $new_image = imagerotate($new_image, 90, 0);
    }
    $imgt($new_image, $uploadpath);
    return file_exists($uploadpath);
}
</code></pre>