Some cameras include an orientation tag in the metadata section of the file itself. This means that the device itself can show it in the correct orientation every time, regardless of the orientation of the image in its original data.
Windows doesn't seem to support reading this orientation tag and instead just reads the pixel data and displays it as is.
The solution would be to either change the orientation tag in the metadata with scary images based on each image, OR
Use the exif_read_data() PHP function to read the orientation and orient the image as follows:
<?php $image = imagecreatefromstring(file_get_contents($_FILES['image_upload']['tmp_name'])); $exif = exif_read_data($_FILES['image_upload']['tmp_name']); if(!empty($exif['Orientation'])) { switch($exif['Orientation']) { case 8: $image = imagerotate($image,90,0); break; case 3: $image = imagerotate($image,180,0); break; case 6: $image = imagerotate($image,-90,0); break; } }
Literature:
Pablo canseco
source share