skip to Main Content

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 AppHttpControllers;

use IlluminateHttpRequest;
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:

  • Laravel 8.54
  • Windows 11
  • XAMPP
  • PHP Version 8.0.7

phpinfo():

  • Compiler Visual C++ 2019
  • Architecture x64
  • imagick module version 3.5.1
  • Imagick compiled with ImageMagick version ImageMagick 7.0.7-11 Q16 x64 2017-11-23
  • Imagick using ImageMagick library version ImageMagick 7.0.7-25 Q16
    x64 2018-03-04
  • ImageMagick release date 2018-03-04
  • ImageMagick number of supported formats: 240

Can anyone help?

2

Answers


  1. 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/

    Login or Signup to reply.
  2. 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 Filesgsgs10.00.0bin
    

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

    C:Program Filesgsgs10.00.0bin
    

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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search