Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gd driver is unable to init from Imagick object. Intervention Error initFromImagick #1

Open
SimeonDominiq opened this issue Jun 28, 2018 · 5 comments

Comments

@SimeonDominiq
Copy link

No description provided.

@jianhuawang
Copy link
Owner

Imagick is another Image Driver, and have powerful ability. If you want to use it you must install is ahead.

Gd drive does not handle pdf file.

more information for you:

http://php.net/manual/en/book.imagick.php
http://php.net/manual/en/imagick.setup.php

@SimeonDominiq
Copy link
Author

@jianhuawang Thanks...
I have installed both imagick and ghostscript on my windows system and working fine. But when i try to use this class in my controller, It throws this exception

vendor\intervention\image\src\Intervention\Image\Gd\Decoder.php

public function initFromImagick(\Imagick $object)
{
    throw new \Intervention\Image\Exception\NotSupportedException(
        "Gd driver is unable to init from Imagick object."
    );
}

This is how I'm instatiating the class
use PdfToImage;
PdfToImage::pdfFile('test.pdf')->saveImage();

@SimeonDominiq
Copy link
Author

@jianhuawang The bug is coming from this Method

` public function saveImage($pagePointer = 1)
{
$imageWriter = $this->getImagick($pagePointer);
//dd($this->format, $this->quality);

    //Check this line where you are using Image intervention to make and encode the file
    $imageContent = Image::make($imageWriter)->encode($this->format, $this->quality);

    $distDir = $this->solveDistDir();
    $imageName = $this->solveDistImageName($pagePointer);

    $imageStorage = Storage::disk($this->imageDisk);

    return $imageStorage->put($distDir . DIRECTORY_SEPARATOR . $imageName, $imageContent);
}`

This line where Image Intervention is being called to be precise
$imageContent = Image::make($imageWriter)->encode($this->format, $this->quality);

@jianhuawang
Copy link
Owner

Did you install imagick extension?

download from here: http://pecl.php.net/package/imagick/3.4.3/windows
There are several steps of installing imagick extension for php. After finish, run phpinfo();

imagick

I suggest you search the operations detail by google or other search engine.

@SimeonDominiq
Copy link
Author

@jianhuawang Both Imagick and Ghostscript is installed and working after reading the Error carefully and going through Intervention Decode.php class, I saw that the GD driver won't work on Imagick file. So i needed to change the default driver from GD to Imagick by adding this line of code in the saveImage method in your class
//Set Intervention to use imagick as its driver rather than the default GD Image::configure(array('driver' => 'imagick'));

public function saveImage($pagePointer = 1) { $imageWriter = $this->getImagick($pagePointer); //Set Intervention to use imagick as its driver rather than the default GD Image::configure(array('driver' => 'imagick')); $imageContent = Image::make($imageWriter)->encode($this->format, $this->quality); $distDir = $this->solveDistDir(); $imageName = $this->solveDistImageName($pagePointer); $imageStorage = Storage::disk($this->imageDisk); return $imageStorage->put($distDir . DIRECTORY_SEPARATOR . $imageName, $imageContent); }

And this was able to fix it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants