image icon indicating copy to clipboard operation
image copied to clipboard

Orientation Imagick

Open medspec opened this issue 3 years ago • 3 comments

I am running laravel with s3 storage and trying to orientate() the image. But that fails.

I checked the Intervention\Image\Imagick\Commands\ExifCommand file, which has a function dontPreferExtension(). is there a way i can use that? because when i hardcode it to false, the orientation works

medspec avatar Mar 19 '21 10:03 medspec

use Intervention\Image\Imagick\Commands\ExifCommand;
use Intervention\Image\Imagick\Driver;

class MyImagickDriver extends Driver
{
    /**
     * Executes named command on given image
     *
     * @param  Image  $image
     * @param  string $name
     * @param  array $arguments
     * @return \Intervention\Image\Commands\AbstractCommand
     */
    public function executeCommand($image, $name, $arguments)
    {
        if ($name === 'exif') {
            $command = new ExifCommand($arguments);
            $command->dontPreferExtension();
            $command->execute($image);
            return $command;
        }

        return parent::executeCommand($image, $name, $arguments);
    }

    public function getDriverName()
    {
        return 'Imagick';
    }
}

frederikbosch avatar Aug 24 '22 13:08 frederikbosch

use Intervention\Image\Imagick\Commands\ExifCommand;
use Intervention\Image\Imagick\Driver;

class MyImagickDriver extends Driver
{
    /**
     * Executes named command on given image
     *
     * @param  Image  $image
     * @param  string $name
     * @param  array $arguments
     * @return \Intervention\Image\Commands\AbstractCommand
     */
    public function executeCommand($image, $name, $arguments)
    {
        if ($name === 'exif') {
            $command = new ExifCommand($arguments);
            $command->dontPreferExtension();
            $command->execute($image);
            return $command;
        }

        return parent::executeCommand($image, $name, $arguments);
    }

    public function getDriverName()
    {
        return 'Imagick';
    }
}

@frederikbosch Hi, Could you please give more detail for the use of this code?

everyx avatar Aug 24 '22 14:08 everyx

If you want to use the dontPreferExtension method in the ExifCommand class, you have to create your own driver and overload the executeCommand method . However, you are also required to overload the getDriverName method and return Imagick as the driver name to make sure all other command keep working.

Then create the ImageManager as is explained in the usage overview.

new ImageManager(['driver' => new MyImagickDriver()]);

frederikbosch avatar Aug 25 '22 07:08 frederikbosch