kingreigns Posted May 1, 2017 Share Posted May 1, 2017 I have this short php code which will allow the image to be rotated correctly (based on their exif data) //IMAGE ROTATION// $image_name = "./postimgs/".$post_img; $rotated_imagename = "./postimgs/rotated_".$post_img; $exif_data = exif_read_data($image_name); function orientation($exif_data){ foreach ($exif_data as $key => $value) { if(strtolower($key)=="orientation") { return $value; } } } // function function orientation_flag($orientation) { switch ($orientation): case 1: return 0; case 8: return 90; case 3: return 180; case 6: return 270; endswitch; }// function $orientation = orientation($exif_data); $degrees = orientation_flag($orientation); $image_data = imagecreatefromjpeg($image_name); $image_rotate = imagerotate($image_data, $degrees, 0); imagejpeg($image_rotate, $rotated_imagename); imagedestroy($image_data); imagedestroy($image_rotate); //END IMAGE ROTATION// echo "<img id='placeholder2' src='./postimgs/rotated_$post_img' style = 'object-fit:contain; width:250px; height:137px; margin-left:0px; margin-top:10px; border: 0px solid #dedede;' >"; The only problem with this is that, when uploading a non-jpeg file (png,gif,etc), it would give me a `File not supported exif data` error. Is there any get around with this like - when reading the image is not a jpeg, it would skip all the `exif_data` thing? Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted May 1, 2017 Share Posted May 1, 2017 exif_imagetype() 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.