Grzyb9k
Grzyb9k

Reputation: 183

PHP Imagick dont work with PDF files in Laravel 8, simple ImagickException

I try to use first time Imagick to convert pdf files to images and it dont work for me. When i try use Imagick with images files, its ok and working fine, problem is with PDF files.

My test php controller:


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Imagick;
class NewspaperController extends Controller
{

    /**
     * @throws \ImagickException
     */
    public function show()
    {
        $imgExt = new Imagick();

        $imgExt->readImage(public_path('storage/uploads/test.pdf'));

       $imgExt->writeImages(public_path('storage/uploads/pdf_image_doc.jpg'), false);

        
        return view('xxx');
    }
}

When i open this in browser i get only "ImagickException" simple error.

ImagickException

I working on local, with:

phpinfo():

Can anyone help?

Upvotes: 1

Views: 1623

Answers (2)

Y. Joy Ch. Singha
Y. Joy Ch. Singha

Reputation: 3262

Here is the line of code:

if ($request->has('pdf_file')) 
        {
            $getPdfFile = $request->file('pdf_file');

            $originalname = $getPdfFile->getClientOriginalName();

            $path = $getPdfFile->storeAs('PdfToJpg', $originalname);
        }


        $storagePath = storage_path('app/PdfToJpg/' . $originalname);

         $imagick = new Imagick();

        $imagick->setResolution(600, 600);

        $imagick->readImage($storagePath);

        $imagick->writeImage(storage_path('app/PdfToJpg/download.jpeg')); 

And,

C:\Program Files\gs\gs10.00.0\bin

and rename gswin64.exe to gs.exe And add Environment variables

C:\Program Files\gs\gs10.00.0\bin

I run in php 7.4, Ghost script 10.0 and Imagick ImageMagick-7.1.0-Q16 and laravel 7* Thank you.

Upvotes: 0

Michael Griffiths
Michael Griffiths

Reputation: 36

Imagick has a release candidate that fixes this error. We were experiencing the same issue after upgrading to Laravel 8.

The new release candidate was posted on 11/10/2021 (6 days after this post). https://windows.php.net/downloads/pecl/releases/imagick/3.6.0rc1/

Upvotes: 2

Related Questions