Creating image rotation using Image magic by command line.
Some time image taken from iphone when uploaded on the website gets rotated .We can easily find that the image is rotated and can rotate is back by using the following code.
$rotableImage = array('jpg', 'jpeg', 'JPEG', 'JPG');
if(in_array($fileParts['extension'], $rotableImage)){
$exif = @exif_read_data($tempFile, 0, true);
if(@$exif['IFD0']['Orientation']!='')
{
switch ($exif['IFD0']['Orientation'])
{
case 3:
$cmd="convert $tempFile -rotate 180 $tempFile";
exec($cmd);
break;
case 8:
$cmd="convert $tempFile -rotate 90 $tempFile";
exec($cmd);
break;
case 6:
$cmd="convert $tempFile -rotate 90 $tempFile";
exec($cmd);
break;
}
}
}
If you see closely it is only for JPEG or JPG. We can use this code for only for JPEG and TIFF images as they only have header in which "Orientation" is available which tell us the image is rotated and for rest of the image type "exif_read_data" will return error .
0 Comment(s)