PHP imagick searches for modules/coders in wrong path - php

I've installed ImageMagick, PHP Imagick, Ghostscript on my Windows Server. Everything works fine by cmd prompt and by php exec() function. But it doesn't work via Imagick Class.
This part of code:
$im = new Imagick();
$im->setFormat('PNG');
$im->readImageBlob($this->config->item('system_path')."ftp/MAKRO-INFO/x1.png");
returns ImagickException:
Fatal error: Uncaught exception 'ImagickException' with message 'unable to load module `C:\Windows\system32\config\systemprofile\.magick\IM_MOD_RL_PNG_.dll': An unknown error occurred # error/module.c/OpenModule/1282'
I am very surprised why is Imagick searching for modules in windows/system32/ directory. Of course it doesn't work when access to this path is denied.
My question is, where/how can I change this path (configuration file, registry or enviroment variables)?
This is my phpinfo. As you can see, no modules have been loaded (0 supported formats).
and PATHs:

Found the solution. There was a collision between ImageMagick version and PHP imagick version.
I used these versions:
ImageMagick-6.8.0-3-Q16
php_imagick-3.2.0RC1-5.4-nts-vc9-x86

Related

Where to install GhostScript for imagick used by PHP on XAMPP on Windows

I am trying to use imagick for image processing in PHP and GhostScript for converting PHP files to images. I moved all the needed .dll from the ImageMagick-6.9.3-7-vc11-x86 file downloaded into xampp/php/ext and add the extension = php_imagick.dll line in the php.ini file. The imagick extension is displayed when the phpinfo() is called and I can call the functions of the Imagick class.
However, my problem is that when I tried to convert a pdf file into an image, it gave me the following error message:
">"Fatal error: Uncaught exception 'ImagickException' with message
">"'PDFDelegateFailed `The system cannot find the file specified. ' #
">"error/pdf.c/ReadPDFImage/801' in
">"C:\Users\Raymond\xampp\htdocs\phpTest\index.php:45 Stack trace: #0
">"C:\Users\Raymond\xampp\htdocs\phpTest\index.php(45):
Imagick-">">__construct('C:\Users\Raymon...') #1 {main} thrown in
">"C:\Users\Raymond\xampp\htdocs\phpTest\index.php on line 45
I figured the problem was caused because my imagick extension on xampp can not locate GhostScript. I downloaded GhostScript to my computer.

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 some formats missing

I've installed Imagick to my uwamp server and ImageMagick. After server restart, I had the following phpinfo:
As you see, there is Imagick installed and plenty of supported formats. But some important formats missing (jpeg, png). I was curious about that, so I tried to run some conversion. The folowing error appeard:
Fatal error: Uncaught exception 'ImagickException' with message 'unable to load module `C:\Program Files (x86)\ImageMagick-6.9.1-Q16\modules\coders\IM_MOD_RL_SVG_.dll'
Its's strange, because I checked that the module is in the path, so why it can't be loaded? Any ideas?
EDIT:
C:\Program Files (x86)\ImageMagick-6.9.1-Q16\modules\coders have the following content:
You'll need to install libpng and libjpeg. Depending on how you installed ImageMagick & Imagick, it might be as simple as adding the shared/dynamic library, or linking to them.
Info on resource and delegates here, and source-code to delegates can also be found here

ImagickException with message Postscript delegate failed on MAMP 3.0.5

Im trying to convert a PDF to a png file using MAMP 3.0.5. I know that my PHP code works as it works fine on our Linux server...
I have setup MAMP 3.0.5 on my Mac OSX 10.8.5 and when I run the script to convert the PDF to png file I get the following error:
Fatal error: Uncaught exception 'ImagickException' with message 'Postscript delegate failed `/Applications/MAMP/htdocs/timesheets.com/saas/public_html/timesheets1/timesheets/Daisy_Morris_53635951154c7.pdf': No such file or directory # error/pdf.c/ReadPDFImage/713'<
Please help, this is driving me crazy!
I just found this blog post: http://lamp-ios.com/?p=216
The problem was that MAMP pro's PATH variable doesn't include the path the ghost script, which ImageMagick uses under the hood on PDF manipulation.
The steps to fix it were:
get the path to ghost script by typing "which gs" in the console
in your php:
putenv('PATH=' . getenv('PATH') . ':/opt/local/bin/');
where /opt/local/bin/ is the path to your gs install
This might help. I just ran into the same issue and solved it a few hours later.
My first instinct was to make sure PHP was looking at the right PATH. For me, it was this:
putenv('PATH=' . getenv('PATH') . ':/usr/local/bin');
That didn't seem to help on its own, but I left the code in there because at some point GhostScript is going to need to know where to find those libpng files.
My next step was to examine MAMP's Apache error log. I found this as the probable culprit:
dyld: Library not loaded: /usr/local/lib/libpng16.16.dylib
Referenced from: /usr/local/bin/gs
Reason: Incompatible library version: gs requires version 29.0.0 or later, but libpng16.16.dylib provides version 23.0.0
Very strange, because my libpng in /usr/local/lib is up to date (1.6.12).
After much trial and error, I found that as of 3.0.5, MAMP is overriding with its own libpng files, in /Applications/MAMP/Library/lib
I removed libpng16.16.dylib from /Applications/MAMP/Library/lib, restarted MAMP, tried again, and got this error:
dyld: Library not loaded: /usr/local/lib/libfreetype.6.dylib
Referenced from: /usr/local/bin/gs
Reason: Incompatible library version: gs requires version 18.0.0 or later, but libfreetype.6.dylib provides version 17.0.0
Well that's something different, so I removed libfreetype.6.dylib from /Applications/MAMP/Library/lib as well, and restarted MAMP.
At this point, everything began working. At least for me, the two steps were to make sure PHP's PATH is looking at the right directory, and then to remove the offending files from MAMP's included libpng library, forcing PHP to use the up-to-date libpng files in /usr/local/lib.

ImageMagick failed in XAMPP

I had installed ImageMagick in XAMPP 1.8.1 come with PHP 5.4.7. I want to have thumb generate in JPG while uploading PDF file. I follow this guide (http://www.elxsy.com/2009/07/installing-imagemagick-on-windows-and-using-with-php-imagick/) to installing the dll and test run the script, but end up I get below error:
Fatal error: Class 'imagick' not found in C:\...
What's wrong come with this installation?
SOLUTION:
I just got it to work by installed ImageMagick 6.8.0. I use the package here: http://valokuva.org/?p=197
set the path in environment variable
First go to the system properties and click on environment variables and give the path of imagemagick library path in PATH variable.
C:\ImageMagick

Categories