Php Imagick not working after ubuntu upgrade - php

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.

Related

XAMPP x64 and Imagick in Windows 10 doesn't work

I'm trying to install imagick on XAMPP x64 with PHP x64 architecture, I followed those steps:
1 - Download and install ImageMagick for Windows, I installed this version: ImageMagick-7.0.9-9-Q16-x64-dll.exe
2 - Download Imagick for PHP, I downloaded this version php_imagick-3.4.4-7.2-ts-vc15-x64, added the php_imagick.dll in xampp/php/ext folder and enabled the extension in php.ini.
3 - Download required Imagick binaries, I downloaded this bin ImageMagick-7.0.7-11-vc15-x64 and added them in xampp/apache/bin folder.
4 - Download Ghostscript, I installed this version gs950w64.
Then I restart XAMPP with all related services. In the phpinfo I see the imagick extension and it works but if I run this code I get an ERR_CONNECTION_RESET error.
$im = new Imagick();
$im->pingImage(realpath('sample.pdf'));
echo $im->getNumberImages();
Here the phpinfo:
What's the problem?
Thanks
UPDATE:
If I run "composer show --platform" I get this warning "PHP Warning: Version warning: Imagick was compiled against ImageMagick version 1799 but version 1801 is loaded. Imagick will run but may behave surprisingly in Unknown on line 0". I don't know if it is relevant.
The problem appears only with PDF files, if I run the same code with a jpg image it works correctly
a bit late, but after a hard day of trying to get Windows + PHP + imagick + Ghostview running I want to share my solution.
Using PHP 7.2 (Tread Safe, WIN 32, CGI/FastCGI) I installed the matching PHP-imagick-version without problems (php_imagick-3.4.4-7.2-ts-vc15-x86.zip)
(Tip for CGI/FastCGI: php_imagick.dll as described into the PHP-ext-directory, but the other 150 imagick-dlls to cgi-bin-folder)
Afterwards I installed the actual win32-version (gs952w32.exe) and got lots of "Internal Server Error" and the apache-error-log growed...:-(
Solution:
Moving backwards in older gs-releases (https://github.com/ArtifexSoftware/ghostpdl-downloads/releases) i succeeded to get a running installation with 9.25 (gs925w32.exe).
BTW:
On my private linux-machine the same installation of PHP, Imagick and Ghostview needed only a few minutes...

ImageMagick Errors: Reading PDF

I am on Win Server 2012 IIS 8, PHP 5.6, Imagick Module 3.1.2, ImageMagick 6.8.7-2 2013-10-18 Q16.
I have read through all the Postscript delegate failed errors and have done the following:
- Installed GhostScript
- Checked that GS and Imagick is in the PATH var
- Checked that I can use convert in the command prompt (Does work)
- PHP exec("whoami") returns nt authority\iusr which I added for Full Control
- I tried using full paths backslashes () double-backslashes (\) foward-slashes (/)
- I don't think it has anything to do with the path because if I try the same code on a jpg with no path it works. Script and files are in the same path.
Here is my PHP code:
<?php
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(E_ALL);
echo exec("whoami"); echo "<br/>";
echo exec("convert.exe dr.pdf dr.jpg 2>&1"); // Does not work and gives below error
echo "<br/>";
$im = new imagick();
$im->readimage("dr.pdf");
$pages = $im->getNumberImages();
echo $pages;
?>
Output:
nt authority\iusr convert.exe: no images defined `dr.jpg' #
error/convert.c/ConvertImageCommand/3145.
Fatal error: Uncaught exception 'ImagickException' with message
'Postscript delegate failed `dr.pdf': No such file or directory #
error/pdf.c/ReadPDFImage/682' in D:\WWW\DEMO\data\temp\test.php:13
Stack trace: #0 D:\WWW\DEMO\data\temp\test.php(13):
Imagick->readimage('dr.pdf') #1 {main} thrown in
D:\WWW\DEMO\data\temp\test.php on line 13
Any help would be greatly appreciated.
Regards
Johan
To anyone who might run into the same problem:
Change the permissions of C:\Windows\Temp to include Full Control for IIS_IUSRS and Users
After I did this everything seems to work!
Note: I had to upgrade to the latest PECL Imagick Module to see the full error that GhostScript was returning, which showed that GhostScript was trying to perform the conversion in windows Temp folder.
It was strange that my php script worked from a command line but not from the website. But obviously it was a permission issue.
I'm posting the following Installation steps for whoever runs into the same problem (Or if I need a guide in the future and I forgot :) )
On Windows 2012 Server with IIS 8
Install Win Platform Installer (https ://www.microsoft.com/web/downloads/platform.aspx)
Go to IIS Manager and open Web Platform Installer and Install PHP 5.6
Download ImageMagick x86 DLL install from here: http://www.imagemagick.org/download/binaries/ImageMagick-6.9.1-9-Q16-x86-dll.exe
Install ImageMagick and ensure that $_SERVER["Path"] has the ImageMagick path configured.
Download the latest PECL ImageMagick x86 NonThreadSafe PHP module here: http://windows.php.net/downloads/pecl/releases/imagick/3.3.0RC2/php_imagick-3.3.0rc2-5.6-nts-vc11-x86.zip
Copy all the PECL ImageMagick DLL files into PHP\ext
Add extension=php_imagick.dll in your php.ini file
Download and Install GhostScript x64 here: http: //downloads.ghostscript.com/public/gs916w64.exe (Not x86 as ImageMagick delegates to the 64bit GhostScript)
Ensure that GhostScript Path is in $_SERVER["Path"] variable (C:\Program Files\gs\gs9.16\bin)
IMPORTANT LAST STEP: Add user rights to C:\Windows\Temp for IIS_USRS and Users
Restart Server (Usually required for PHP to see the paths)
What always helped me is testing my most basic script through a command prompt> php.exe test.php
This will almost always show you errors if you did something wrong with the install or if you need a VC Redist. Where a website query doesn't always show you the startup errors.

php imagick error when pdf involved

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

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')
?>

Installing ImageMagick on WAMP (Win7) : Class not found

I've tried just about everything I've been able to find and so far nothing seems to work.
Regardless of what I install, php always returns "Fatal error: Class 'Imagick' not found."
My system is:
Win7, 64bit
Apache 2.2.21
PHP 5.3.10
PHP Extension Build: API20090626,TS,VC9
I've installed various versions of ImageMagick (6.6.7, 6.7.1, and 6.8.5, both x86 and x64), and used dll's (VC6 and VC9) from http://chernoivan.ru/tools/imagemagick-dlls.html, http://www.sk89q.com/2010/03/vc6-windows-binaries-for-imagick-2-3-0/, and http://valokuva.org/?m=201211.
WAMP shows the extension as being activated (I added extension=php_imagick.dll to my php.ini file)
phpinfo() though never shows anything specific to imagick besides some path variables and the script itself:
<?php
header('Content-type: image/jpeg');
$image = new Imagick('image.jpg');
// If 0 is provided as a width or height parameter,
// aspect ratio is maintained
$image->thumbnailImage(100, 0);
echo $image;
?>
always says class not found.
What could the problem at this point be?
Discovered the problem.
ImageMagick (at least from what I can tell) will not work on a x64 installation of php.
Fix was to install a different version of WAMP with a x86 build of php.
Used the dll found here: http://www.peewit.fr/imagick/
With ImageMagick-6.8.1-8-Q16-x64-dll.exe found here: http://image_magick.veidrodis.com/image_magick/binaries/

Categories