Re: Some images rotate, why?
Posted: 12 May 2016, 18:24
Hi, I will try to implement it in next version. The code you have set, includes some problematic parts:
1) it does not check for mimetype and tries to get information from images which do not have exif data
2) there is no handling for orientation in some cases (e.g. 1)
For now the code which prevents from some error looks like, if you use the code added above, please try to correct it so you will not get any errors:
The first row should be not removed. E.g. in case you get orientation = 1, then the list will be not done so it must be done as default and in case, there can be used exif orientation, it will be overwritten.
Exif_read_data should be used only for images which use exif.
Jan
1) it does not check for mimetype and tries to get information from images which do not have exif data
2) there is no handling for orientation in some cases (e.g. 1)
For now the code which prevents from some error looks like, if you use the code added above, please try to correct it so you will not get any errors:
Code: Select all
list($w, $h, $type) = GetImageSize($fileIn);
// Read EXIF data from image file to get the Orientation flag
$exif = null;
if (function_exists('exif_read_data') && $type == IMAGETYPE_JPEG ) {
$exif = @exif_read_data($fileIn);
}
// GetImageSize returns an array of width, height, IMAGETYPE, "height=x width=x" (string)
// The EXIF Orientation flag is examined to determine if width and height need to be swapped, i.e. if the image will be rotated in a subsequent step
if(isset($exif['Orientation']) && !empty($exif['Orientation'])) {
switch($exif['Orientation']) {
case 8: // will need to be rotated 90 degrees left, so swap order of width and height
list($h, $w, $type) = GetImageSize($fileIn);
break;
case 3: // will need to be rotated 180 degrees so don't swap order of width and height
list($w, $h, $type) = GetImageSize($fileIn);
break;
case 6: // will need to be rotated 90 degrees right, so swap order of width and height
list($h, $w, $type) = GetImageSize($fileIn);
break;
}
}Exif_read_data should be used only for images which use exif.
Jan