I have images on a website on wich i am fooling arround with a bit.
i want to make thumbs from bigger pictures, that i worked out.
but when resizing the pictures to smaller versions they tend to get displayed rotated because the orientation is set wrong.
I found below function to repair that issue and i tried to add some code to it so it will work also with other then jpg files.
the files i am currently trying to resize are all jpg btw.
I bet you all can see i am no master at php.... forgive me for that....
i hope someone can point me away from the error i am getting with below function.
i get the following error:
"Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 2988 bytes) "
The line that gives the error is
$img = imagerotate($img, $deg, 0);function correctImageOrientation($filename, $type) {
//echo $filename; exit;
if (function_exists('exif_read_data')) {
$exif = exif_read_data($filename);
//echo $exif['Orientation'].'<br>';
//print_r($exif);
if($exif && isset($exif['Orientation'])) {
$orientation = $exif['Orientation'];
if($orientation != 1){
switch ($type)
{
case IMAGETYPE_JPEG:
$img = imagecreatefromjpeg($filename);
break;
case IMAGETYPE_GIF:
$img = imagecreatefromgif($filename);
break;
case IMAGETYPE_PNG:
$img = imagecreatefrompng($filename);
break;
case IMAGETYPE_JPG:
$img = imagecreatefromjpeg($filename);
break;
case IMAGETYPE_WBMP:
$img = imagecreatefromwbmp($filename);
break;
}
$deg = 0;
switch ($orientation) {
case 3:
$deg = 180;
break;
case 6:
$deg = 270;
break;
case 8:
$deg = 90;
break;
}
//echo $img;
//echo $deg;
//exit;
if ($deg) {
$img = imagerotate($img, $deg, 0);
}
// then rewrite the rotated image back to the disk as $filename
switch ($type)
{
case IMAGETYPE_JPEG:
imagejpeg($img, $filename);
break;
case IMAGETYPE_GIF:
imagegif($img, $filename);
break;
case IMAGETYPE_PNG:
imagepng($img, $filename);
break;
case IMAGETYPE_JPG:
imagepng($img, $filename);
break;
case IMAGETYPE_WBMP:
image2wbmp($img, $filename);
break;
}
} // if there is some rotation necessary
} // if have the exif orientation info
} // if function exists
}