Using imgine for resize image

Hello, in my projects I have always used the imagine library to upload and resize images. In my last project a user reported an image that when uploading it and using the thumbnail method, it was rotated and remained rotated 180°.

Doing some research I realized that it is possible that the image is really inverted but that modern browsers and systems read the EXFI and display it correctly.

I also found that the imgine library uses GD2 by default, and that this connector is not able to understand the EXFI information, so I guess my solution is to use the imagick connector.

The function I am trying to implement is the following

use yii\imagine\Image;
use Imagine\Gd;
use Imagine\Image\Box;
use Imagine\Image\BoxInterface;

public function actionCreate(){
//There are others lines previusly
                    Image::$driver = [Image::DRIVER_IMAGICK];
                    $img_t = Image::getImagine()->open($ruta_imgs . $modelo_editar->tax_imagenfrontalizquierda);
                    $img_t_thumb =  $img_t->thumbnail(new Box(265, 150));
                    $img_t_thumb_rotada = $this->revisa_rotacion($img_t_thumb);
}
    protected function revisa_rotacion($imagen){
        $orientation = $imagen->getImageOrientation();
        switch ($orientation) {
            case 8:
                $imagen->rotateimage("#000", -90);
                break;
            case 3:
                $imagen->rotateimage("#000", 180);
                break;
            case 6:
                $imagen->rotateimage("#000", 90);
                break;
        }
        return $imagen;
    }

but i get the following error.

Call to undefined method Imagine\Imagick\Image::getImageOrientation()

Can you help me, please?

This is strange. I had the same problem with my own custom code for processing images. My script couldn’t recognize the rotated image and did the resizing with wrong rotation. I also find out, that the reason why I see the picture in the beginning correctly is the ability of browsers.

In the end, I was able to do a small update to teach my code to handle this - just used exif_read_data() and $exif[‘Orientation’] to get the rotation and then properly rotate the image on other side.

But the reason why I write this is, that with Yii and yiisoft/yii2-imagine, I didn’t have to do any of that, since the extension do that for me. So it’s strange to hear, that it doesn’t work for you.

Btw what is this line?
Image::$driver = [Image::DRIVER_IMAGICK];
Are you trying to change Class property in a “static manner”? This doesn’t seems to be a good or working solution.
Isn’t here a method to properly set the driver when on the created object?

Why would you even do that? The default library is Gmagick and it should handle the rotation right.