yii2-imagine
yii2-imagine copied to clipboard
After save image vertical photo rotated by horizontal
Hi i upload file with UploadedFile and when save without this lib image have vertical orientation, but when i used jpeg_quality image rotated horizontal. Using GD library
$uploadFile = UploadedFile::getInstanceByName('file'.yii::$app->request->post('name'));
$uniq = uniqid().'.'.str_replace('image/','', $uploadFile->type);
$filePut = Helper::filePut( $uniq, file_get_contents( $uploadFile->tempName ));
Image::frame($filePut['path'])->save($filePut['path'], ['jpeg_quality' => 60]);
$file->content = file_get_contents($filePut['path']);
I guess by orientation you mean EXIF property. Is EXIF written at all?
array (size=66)
'FileName' => string '1.JPG' (length=5)
'FileDateTime' => int 1508223150
'FileSize' => int 3563877
'FileType' => int 2
'MimeType' => string 'image/jpeg' (length=10)
'SectionsFound' => string 'ANY_TAG, IFD0, THUMBNAIL, EXIF, GPS' (length=35)
'COMPUTED' =>
array (size=8)
'html' => string 'width="4032" height="3024"' (length=26)
'Height' => int 3024
'Width' => int 4032
'IsColor' => int 1
'ByteOrderMotorola' => int 1
'ApertureFNumber' => string 'f/1.8' (length=5)
'Thumbnail.FileType' => int 2
'Thumbnail.MimeType' => string 'image/jpeg' (length=10)
'Make' => string 'Apple' (length=5)
'Model' => string 'iPhone 7' (length=8)
'Orientation' => int 6
'XResolution' => string '72/1' (length=4)
'YResolution' => string '72/1' (length=4)
'ResolutionUnit' => int 2
'Software' => string '10.3.3' (length=6)
'DateTime' => string '2017:08:26 18:59:02' (length=19)
'YCbCrPositioning' => int 1
'Exif_IFD_Pointer' => int 206
'GPS_IFD_Pointer' => int 1662
'THUMBNAIL' =>
array (size=6)
'Compression' => int 6
'XResolution' => string '72/1' (length=4)
'YResolution' => string '72/1' (length=4)
'ResolutionUnit' => int 2
'JPEGInterchangeFormat' => int 2066
'JPEGInterchangeFormatLength' => int 12081
'ExposureTime' => string '1/25' (length=4)
'FNumber' => string '9/5' (length=3)
'ExposureProgram' => int 2
'ISOSpeedRatings' => int 32
'ExifVersion' => string '0221' (length=4)
'DateTimeOriginal' => string '2017:08:26 18:59:02' (length=19)
'DateTimeDigitized' => string '2017:08:26 18:59:02' (length=19)
'ComponentsConfiguration' => string '�' (length=4)
'ShutterSpeedValue' => string '6691/1440' (length=9)
'ApertureValue' => string '2159/1273' (length=9)
'BrightnessValue' => string '7352/2315' (length=9)
'ExposureBiasValue' => string '0/1' (length=3)
'MeteringMode' => int 5
'Flash' => int 16
'FocalLength' => string '399/100' (length=7)
'SubjectLocation' =>
array (size=4)
0 => int 999
1 => int 1659
2 => int 314
3 => int 314
'MakerNote' => string 'Apple iOS' (length=9)
'SubSecTimeOriginal' => string '779' (length=3)
'SubSecTimeDigitized' => string '779' (length=3)
'FlashPixVersion' => string '0100' (length=4)
'ColorSpace' => int 65535
'ExifImageWidth' => int 4032
'ExifImageLength' => int 3024
'SensingMethod' => int 2
'SceneType' => string '' (length=1)
'ExposureMode' => int 0
'WhiteBalance' => int 0
'FocalLengthIn35mmFilm' => int 28
'SceneCaptureType' => int 0
'UndefinedTag:0xA432' =>
array (size=4)
0 => string '399/100' (length=7)
1 => string '399/100' (length=7)
2 => string '9/5' (length=3)
3 => string '9/5' (length=3)
'UndefinedTag:0xA433' => string 'Apple' (length=5)
'UndefinedTag:0xA434' => string 'iPhone 7 back camera 3.99mm f/1.8' (length=33)
'GPSLatitudeRef' => string 'N' (length=1)
'GPSLatitude' =>
array (size=3)
0 => string '47/1' (length=4)
1 => string '6/1' (length=3)
2 => string '4323/100' (length=8)
'GPSLongitudeRef' => string 'E' (length=1)
'GPSLongitude' =>
array (size=3)
0 => string '39/1' (length=4)
1 => string '25/1' (length=4)
2 => string '2273/100' (length=8)
'GPSAltitudeRef' => string '�' (length=1)
'GPSAltitude' => string '18499/378' (length=9)
'GPSTimeStamp' =>
array (size=3)
0 => string '15/1' (length=4)
1 => string '59/1' (length=4)
2 => string '199/100' (length=7)
'GPSSpeedRef' => string 'K' (length=1)
'GPSSpeed' => string '1230/29771' (length=10)
'GPSImgDirectionRef' => string 'T' (length=1)
'GPSImgDirection' => string '40324/125' (length=9)
'GPSDestBearingRef' => string 'T' (length=1)
'GPSDestBearing' => string '40324/125' (length=9)
'GPSDateStamp' => string '2017:08:26' (length=10)
'UndefinedTag:0x001F' => string '8/1' (length=3)
https://stackoverflow.com/a/13963783/8092443
work fine if rotated image
$image = Image::getImagine()->open($filePut['path']);
$exif = exif_read_data($filePut['path']);
if (!empty($exif['Orientation'])) {
switch ($exif['Orientation']) {
case 3:
$image->rotate(180);
break;
case 6:
$image->rotate(90);
break;
case 8:
$image->rotate(-90);
break;
}
}
$image->save($filePut['path'], ['jpeg_quality' => 60]);
for 6 set 90 angle, and -90 for 8. in stackoverflow writen reverse
@nemozar can you compare EXIF of source and result image? Probably only value of "Orientation" matters.
$image = Image::getImagine()->open($filePut['path']);
$exif = exif_read_data($filePut['path']);
if (!empty($exif['Orientation'])) {
switch ($exif['Orientation']) {
case 3:
$image->rotate(180);
break;
case 6:
$image->rotate(90);
break;
case 8:
$image->rotate(-90);
break;
}
}
$image->save($filePut['path'], ['jpeg_quality' => 60]);
This method helped me. I thought it will automatically align the image according to EXIF. Because download the wrong way the photo makes no sense.