I have tried a lot of solutions that I have found on internet but nothing is working for me. I am trying to resize and rotate the image depends on exif data but the image is not rotating. Resizing the image is working fine. But the rotation is not working. Below is the function I used to do that.
function resize_imageb($newbfile,$max_resolution){
if(file_exists($newbfile)){
$original_image = imagecreatefromjpeg($newbfile);
$exif = exif_read_data($newbfile, 0, true);
if(!empty($exif['Orientation'])) {
switch($exif['Orientation']) {
case 8:
$original_image = imagerotate($original_image,90,0);
break;
case 3:
$original_image = imagerotate($original_image,180,0);
break;
case 6:
$original_image = imagerotate($original_image,-90,0);
break;
}
}
$original_width = imagesx($original_image);
$original_height = imagesy($original_image);
$ratio = $max_resolution/$original_width;
$new_width = $max_resolution;
$new_height = $original_height * $ratio;
if($new_height > $max_resolution){
$ratio = $max_resolution / $original_height;
$new_height = $max_resolution;
$new_width = $original_width * $ratio;
}
if($original_image){
$new_image = imagecreatetruecolor($new_width,$new_height);
imagecopyresampled($new_image, $original_image, 0, 0, 0, 0,$new_width, $new_height, $original_width, $original_height);
imagejpeg($new_image,$newbfile,100);
imagedestroy($original_image);
imagedestroy($new_image);
}
}
}
When I check the resized image the Orientation information is gone from exif data however the original image I have uploaded did had the Orientation information. I am not sure what i am missing or doing wrong. Can someone help me with this?
Instead of doing the 2 part (resize and rotate) in one function, I made two functions one for rotation created by Wes and then for resize. First called the rotation function and then resize function.