Reputation: 101
I am doing a project in core php. When i upload images which taken from mobile phone , it will display as inverted images. i am using exif_read_data function to get the orientation of image.and according to its value rotate the image. But i didn't get the orientation of all images.Is there any method to get the orientation of image?
This is the code
$exif_data = @exif_read_data($tmp_name);
if(!empty($exif_data['Orientation'])) {
switch($exif_data['Orientation']) {
case 8:
$image_p = imagerotate($image_p,90,0);
break;
case 3:
$image_p = imagerotate($image_p,180,0);
break;
case 6:
$image_p = imagerotate($image_p,-90,0);
break;
}
}
Upvotes: 0
Views: 1825
Reputation: 480
Well, you can check for the width and height of the image:
list($width, $height) = getimagesize('your-image.jpg'); // or other image ext
if ( $width > $height ) {
// Landscape image
}
elseif ( $width < $height ) {
// Portrait
}
else {
// Square
}
PS:
EXIF headers tend to be present in JPEG/TIFF images .. See here.
Resource for
getimagesize()
here.
Upvotes: 0