Imagick / imagick

🌈 The Imagick PHP extension 🌈
http://pecl.php.net/imagick
Other
548 stars 138 forks source link

PHP script - Fatal error when try to convert PDF to JPG on XAMPP #480

Open ghost opened 3 years ago

ghost commented 3 years ago

Hi, I need to run a php script on localhost and I'm using XAMPP for that. I installed everything that I needed and I tried to convert PNG to JPG - everything went fine. I made another attempt to convert the first page of the PDF file to JPG - this time i got Fatal error: at C:\xampp\htdocs\pdf-ocr\test.php on line 3. I read that I am missing ghostscript which is required to work with PDF files, but I have no idea how to install GS on a localhost. I installed GS in C:\Program Files\gs\gs9.55.0 but the error still persists. I am asking for help, I have been working on solving the problem for 2 days ...

System: Windows 10 Compiler: Visual C++ 2017 Architecture: x64 Thread Safety: enabled Imagick Version: 3.5.1

Installation process:

  1. ImageMagick - I moved all DLL files into C:\xampp\apache\bin
  2. PHP Imagick - I moved php_imagick.dll to C:\xampp\php\ext
  3. I added extension=php_imagick.dll to C:\xampp\php\php.ini

Result:

image

Script:

<?php $imagick = new Imagick(); $imagick->readImage(__DIR__ . '/uploads/userfile.pdf[0]'); $imagick->setResolution(300, 300); $imagick->setImageCompressionQuality(100); $imagick->writeImages(__DIR__ . '/uploads/images/page-0.jpg', false); ?>

Danack commented 3 years ago

tbh, I don't really touch windows so am unsure. I think try following the instructions here: https://www.ghostscript.com/doc/current/Install.htm#Install_Windows

let me know how you get on? I should probably write how to install that down somewhere....

ghost commented 3 years ago

I installed GS on my computer then I added the environment variable and still nothing.

image

Danack commented 3 years ago

We usually distribute Ghostscript releases for Windows as a binary installer

I think you need to double-click and run that executable....

ghost commented 3 years ago

So there’s no option to run php script on Windows? :/

ghost commented 3 years ago

Maybe there is option to add PATH to GS binary into ImagickPHP? That should solve my problem.