iwyg / jitimage

Just In Time image manipulation (GD, Imagick, imagemagick) with integration for laravel 4
MIT License
95 stars 8 forks source link

Image ORIENTATION #46

Closed abhimanyu003 closed 9 years ago

abhimanyu003 commented 9 years ago

Imagick and GD don't auto orient image correctly.
As described here http://www.impulseadventure.com/photo/exif-orientation.html

For sure we can add custom filter for such, but it will be great if we internally add this. Which auto detect the orientation of the image and corrects it.

I tried to add, but not able overwrite the original height and width of the image after orientation $this->getInfo('width') and $this->getInfo('height') is still giving the older width and height of image even when canvas get rotated.

Filter is working perfectly fine. Below is for imagick

    public function run()
    {
        $orientation = $this->driver->getResource()->getImageOrientation();

        switch ($orientation)
        {
            case imagick::ORIENTATION_BOTTOMRIGHT:
                $this->driver->getResource()->rotateimage("#000", 180); // rotate 180 degrees
                break;

            case imagick::ORIENTATION_RIGHTTOP:
                $this->driver->getResource()->rotateimage("#000", 90); // rotate 90 degrees CW
                break;

            case imagick::ORIENTATION_LEFTBOTTOM:
                $this->driver->getResource()->rotateimage("#000", -90); // rotate 90 degrees CCW
                break;
        }

        // Now that it's auto-rotated, make sure the EXIF data is correct in case the EXIF gets saved with the image!
        $imagick = new Imagick();
        $this->driver->getResource()->setImageOrientation(Imagick::ORIENTATION_TOPLEFT);

    }

Please let me know