Google App Engine中的Php图像轮换

I am trying to fix orientation of images from mobile devices, using EXIF to get the orientation and switch/case to fix the orientation. Apparently my function was working offline and now it's not working on Google Apps Engine. Could Google have a specific function to do this?

The function:

$image = imagecreatefromjpeg($path);
$exif = exif_read_data($path);

if (!empty($exif['Orientation'])) {
    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, $path);
}