This is a backend solution. We dont allow tiff image uploads, so I didnt include the image type check.
$uploadedFile->tempName is the file path eg: "/var/www/site/upload/images/someImage.jpg"
if(exif_imagetype($uploadedFile->tempName) == 2)//2 IMAGETYPE_JPEG
{
$exif = exif_read_data($uploadedFile->tempName);
if(!empty($exif['Orientation']))
{
$image = imagecreatefromjpeg($uploadedFile->tempName);
switch($exif['Orientation'])
{
case 8:
$image = imagerotate($image,90,0);
break;
case 3:
$image = imagerotate($image,180,0);
break;
case 6:
$image = imagerotate($image,-90,0);
break;
}
imagejpeg($image, $uploadedFile->tempName);
}
}