php imagick error when pdf involved - php

When I try to convert the first page of a PDF into JPG through PHP imagick, I get an HTTP 500 error with no log in php_errors.log.
Explanation from IIS: The FastCGI process exited unexpectedly
Error code: 0xc0000417
Two files are created in C:\Windows\Temp, the first one is the PDF read; the other is 0 Kb length.
I am able to perform command line conversions with ImageMagick (convert some.pdf some.jpg). So, ImageMagick and GhostScript are running fine. Also, I am able tho convert between JPG and GIF from PHP scripts.
PHP code:
$im = new Imagick();
$im->setResolution(300,300);
$im->readimage('poster.pdf[0]');
$im->setImageFormat('jpeg');
$im->writeImage('poster.jpg');
$im->clear();
$im->destroy();
My environment:
Windows 7 Professional 64 bit
IIS 7.5
PHP 5.3.6 NTS VC9 via FastCGI
PHP imagick extension v.3.1.2 (5.3 NTS VC9 x86, from PECL)
ImageMagick-6.7.7-0-Q16-windows-dll (x86)
GhostScript 9.07 win32 (x86)
Microsoft Visual C++ 2008 redistributable x86
Path to ImageMagick added to PATH environment variable
Permissions granted to IUSR and IIS_IUSRS in folders C:\Windows\Temp and C:\imagemagick.
So, can anyone give me some guidance to debug this error and have the thing running?

As Danack suggested, ImageMagick MUST be downloaded from the same place imagick was. Compiler version and processor architecture must be respected to match the ones of PHP and GhospScript (in my case, VC9, x86).
Nevertheless, not all versions of ImageMagick availables at this repository appear to be consistent with those of imagick and / or GhostScript. In my case, the combination that finally worked (at second attempt) was:
imagick 3.1.2
ImageMagick 6.8.8
GhostScript 9.07

Related

Php Imagick not working after ubuntu upgrade

I am getting an error while converting pdf to image file on server but working on local system.
My Php Script
$img = new \Imagick();
$image = file_get_contents($file);
$img->readImageBlob($image);
$response = $img->getnumberimages();
Error Occurred
Unrecoverable error: typecheck in .bind
Operand stack:
--nostringval-- typecheck --nostringval-- currentglobal .currentglobal
System Configurations
Local System Configuration
Imagick: ImageMagick 6.7.7-10 2018-09-28
UBUNTU: 14.04 LTS
PHP: PHP 7.0.32-4+ubuntu14.04.1+deb.sury.org+1
gs: 9.25
Server System Configuration
Imagick: ImageMagick 6.8.9-9 Q16 x86_64 2018-09-28
UBUNTU: 16.04.1 LTS
PHP: PHP 7.0.32-0ubuntu0.16.04.1
gs: 9.25
I have trying to revert version of Imagick to 6.7 but not able to revert the version
Also I have try to change policy.xml file but no luck.
Reverting Image Magick most likely won't do you any good anyway, since that is a Ghostscript error message.
Without seeing the input file I can't guess at what's wrong, but in the absence of that you have 2 choices;
1) Revert your Ghostscript version to 9.23 and try again.
2) Try building Ghostscript from source, its possible that the package maintainers have made some change which isn't in the vanilla sources, and is only exposed on the later version of Ubuntu.
You could also try running Ghostscript on the command line and see what happens on the two systems. You'll need to get the command line from polixy.xml and replace the various variables with the correct filenames.
You can try that on both systems to see what happens. Finally, you can compare the binary size of the Ghostscript executable, to see if they are actually the same on the two systems. If they are not you could copy the working one from your local system to your server and see if that works.

Imagick delegates installation on WAMP

I would like to know how to download the correct Imagemagick decode delegates from http://www.imagemagick.org/download/delegates/, as well what to do with them afterwards.
I'm using:
Imagick 3.4.3RC1, 6.9.3-7 Q16 x64 2016-03-27
PHP 5.6.25
WAMP 3.0.0.25 on Windows 7
I've been looking on Imagick and Stackoverflow threads, but the ones I found were mostly concerning errors with the delegates after they had them, and none of them used WAMP. Any help would be appreciated
In the past this has worked by installing ImageMagick and then downloading a compatible imagick PHP extension.
But currently there seems to be a temporary "Catch 22" situation with ImageMagick and imagick.
imagick versions need to be compiled against a specific version of ImageMagick and currently that has not been done for imagick against the new ImageMagick 7 although I am informed by #danack that imagick is ready to be compiled but nobody has done so yet, or at least they have not shared the binary.
Unfortunately ImageMagick do not retain older versions of their install i.e. ImageMagick 6.? so if you dont already have a version of the installer the only availaible one is ImageMagick 7
The Catch 22
Therefore the only versions of imagick available will only work with ImageMagick 6 and you cannot download ImageMagick 6 as the ImageMagick people do not retain old version of their installer.
The work around
However, if you only want ImageMagick to work within a PHP/Apache environment this proceedure works.
The versions of the following must match your WAMPServer, so if you installed WAMPServer 32bit use the 32bit versions of ImageMagick and Imagick, if you use WAMPServer 64bit, use the 64bit versions of ImageMagick and Imagick.
The VC14 versions should work with WAMPServers Apache 2.4.x versions
Download ImageMagick-6.9.3-7-vc14-x86.zip (32bit)
or ImageMagick-6.9.3-7-vc14-x64.zip (64bit)
from http://windows.php.net/downloads/pecl/deps/ depending upon which WAMPServer version you are using i.e. 32bit or 64bit
Download php_imagick-3.4.3-5.6-ts-vc11-x86.zip (32bit)
or php_imagick-3.4.3-5.6-ts-vc11-x64.zip (64bit)
from http://windows.php.net/downloads/pecl/releases/imagick/3.4.3/ depending upon which WAMPServer version you are using i.e. 32bit or 64bit
Create a folder to hold ImageMagick, I used wamp\imagemagick
Unzip whichever of the ImageMagick's you downloaded i.e.
ImageMagick-6.9.3-7-vc14-x86.zip or ImageMagick-6.9.3-7-vc14-x64.zip into the wamp\imagemagick folder
Unzip whichever of the imagick version you downloaded php_imagick-3.4.3-5.6-ts-vc11-x86.zip (32bit) or php_imagick-3.4.3-5.6-ts-vc11-x64.zip (64bit) into a temp folder and copy the php_imagick.dll from the temp folder to your wamp\bin\php\php5.6.25\ext folder
Edit your 'php.inifile to add the extension. Use the wampmanager menus so you edit the correct file
(left click) wampmanager->PHP->php.ini
Add the lineextension=php_imagick.dllinto the section ofphp.inithat contains the otherextension` parameters.
Add the folder to your windows PATH using
Control Panel -> System -> Advanced System Setting
Select the Advanced Tab
Click the Environment Variables Button
Add C:\wamp\imagick; to the PATH variable in the System Variables section
[I dont like adding anything to the PATH for WAMPServer, but I cannot think of a better solution for now and as this way will work for multiple versions of PHP it is not actually so bad]
Start WAMPServer, or restart Apache. It may be necessary to reboot windows, it was for me, but maybe that was because I tried a number of things before I got to this solution.
Check with phpinfo() you should see

Windows PHP Imagick not working

I am trying for 1 days and this php imagick don't work in windows. It shows
ImageMagick number of supported formats: 0
ImageMagick supported formats no value
First I went to official php website from here
http://windows.php.net/download/
And downloaded VC14 x64 Non Thread Safe (2017-May-09 23:02:49) PHP 7.1.5
I extracted it into C:\ProgramData\php and added it to PATH variable.
And from that directory i renamed php.ini -devlopment to php.ini
And changed line 738 to extension_dir = "ext" so that extensions can be loaded in PHP.
Then php must be working now.
I went to http://windows.php.net/downloads/pecl/releases/imagick/3.4.3/
And downloaded php_imagick-3.4.3-7.1-nts-vc14-x64.zip
And from that zip file i extracted php_imagick.dll into C:\ProgramData\php\ext directory
And also from that zip file I extracted CORE_RL_*.dll into C:\ProgramData\php folder.
And I added extension=php_imagick.dll to php.ini file at line 892
After that i went to http://windows.php.net/downloads/pecl/deps
And downloaded ImageMagick-6.9.3-7-vc14-x64.zip and extracted content of that folder to C:\ProgramData\ImageMagick directory. And I added C:\ProgramData\ImageMagick\bin to my path.
I think I have done all configuration.
But when I create index.php and add phpinfo() function to file in desktop and try to run
php -S localhost:8080
and go to localhost:8080 in web browser it shows
imagick module enabled
imagick module version 3.4.3
imagick classes Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator, ImagickKernel
Imagick compiled with ImageMagick version ImageMagick 6.9.3-7 Q16 x64 2016-03-27 http://www.imagemagick.org
Imagick using ImageMagick library version ImageMagick 6.9.3-7 Q16 x64 2016-03-27 http://www.imagemagick.org
ImageMagick copyright Copyright (C) 1999-2015 ImageMagick Studio LLC
ImageMagick release date 2016-03-27
ImageMagick number of supported formats: 0
ImageMagick supported formats no value
Clearly it is not working .Where did I make mistake. Imagik is so painful to install :(
Recently I found this solution:
I went to C:\ProgramData\php and deleted CORE_*.dll file which i copied .
I needed to copy that as doing php -v was showing error at that time.
and after immediately deleting and rebooting server it showed
ImageMagick number of supported formats: 234
I don't know what is happening but i am happy it is working
And above steps will work as documentation for other user who are in problem like me :)

Suddenly getting ImageMagick "no decode delegate" errors?

I run a site that lets people upload JPEGS, that are then resized and have a .png watermark applied over the top of them.
As of today, a lot of the uploads are failing.
Uncaught ImagickException: no decode delegate for this image format `PNG' # error/constitute.c/ReadImage/501
The weird thing is, some still work fine, complete with the watermark.
I did a yum update the other day, and it installed a new version of ImageMagick and -devel and -last-libs, I'm guessing this broke something.
As for the fact that some uploads still work - maybe some of my php-fpm processes are still somehow using the older version?
I'm on CentOS 6.
Can someone point me to a quick fix for this please, my site has hundreds of visitors on it right now, and it's going to hurt me if I can't fix this!
Thanks.
convert -version gives me this:
Version: ImageMagick 6.8.9-1 Q16 x86_64 2014-05-28 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC OpenMP
Delegates: bzlib freetype jpeg lcms tiff x zlib
(Although I have no idea what it showed before things broke).
These are the packages I currently have installed:
ImageMagick-6.7.2.7-4.el6_7.x86_64
ImageMagick-devel-6.7.2.7-4.el6_7.x86_64
ImageMagick-last-libs-6.9.4.1-1.el6.remi.x86_64
php70-php-pecl-imagick-3.4.2-1.el6.remi.x86_64
Have you restart the server (apache or fpm) after the upgrade ?
As for each new version, path to the coders change (as the version is part of the path), so the server need to be restarted.
See: https://github.com/remicollet/remirepo/issues/33

imagickException: Postscript delegate failed imagick IIS

I'm using theses line to convert a pdf to a jpg:
$img = new imagick($url.'[0]');
$im->setImageColorspace(255);
$im->setCompressionQuality(95);
$im->setImageFormat('jpeg');
I have install imagick 3.1.0RC2 with the soft ImageMagick 6.7.7-10 2012-06-27 Q16 (x86). I also have a x86 PHP 5.4.22 non thread and I'm using IIS 8 on a windows server 2012. The php_imagick.dll is for 5.14 nts so it should work. The ghostscript version is gs9.10, I installed 32 and 64 bits. it is working perfectly with the msdos command line but no with PHP.
and then I got this error when I create the object.
ImagickException: Postscript delegate failed
`D:\inetpub\website\sites\default\files\image_2.pdf': No such file or
directory # error/pdf.c/ReadPDFImage/677 in Imagick->__construct()
is it an environment variables problem ?
I've got the imagick folder and the bin folder of ghostscript as windows environment variable.
Any ideas ?
Cheers
I finally found out the answer!
The problem is the temporary folder of windows (c:\windows\temp) (your upload_tmp_dir in php.ini) has to be read and write for the user IUSR or IIS_IUSRS (depending of your IIS version)
Thank you guys for your help
That seems to indicate that imagick can't find the ghostscript executable.
Ensure that the GS executable is in the relevant PATH:
<?php
phpinfo(INFO_ENVIRONMENT);
?>
...search that page for PATH.
If it's not there, add it in whichever script(s) needs it:
<?php
putenv(getenv('PATH').':path/to/ghostscript/executable')
?>

Categories