Image gets saved with wrong orientation

Hello,

I have faced following problem. When i upload a picture via mobile it gets saved with wrong orientation.

After searching, I found that it is possible to check for an image orientation before saving it.

To do it, it is required to read exif data of an image.

Could someone suggest me how could I do it in Yii2.

These are the steps I do to save file:


 

$uploadedFile = UploadedFile::getInstance($picture, 'picture_url');

$rnd = rand(0, 99999999);

$fileName = "{$rnd}-{$uploadedFile}";

$model->picture_url = $fileName;

$uploadedFile->saveAs(Yii::getAlias('@frontend') . '/web/uploads/' . $model->picture_url);

$model->save();



I would look into the gd or imagick php extensions. They both have functions to auto rotate based on exif data. If you have Imagemagick installed on your server you can also use exec() to rotate the image with a command similar to

exec(‘mogrify -auto-orient /path/to/image.jpg’);

Thanks for you answer,

I did some work with php. And it works perfectly fine. However, there are some problems with png extensions.

Any chance that there exist some yii2 extension that work with image manipulation, including auto-rotate based on orientation.

I have searched for it, but didn’t found anything that suits me.

Hi!

Could you please show your solution. Stuck with same issue on image rotation based on exif.

Using Yii2, Imagine

Thanks!

I have tried this extension. It is pretty good, solved my problem