I'm having a weird imagick issue that I can't seem to diagnose.
I have the following source image:
And the following code:
$img = new Imagick($path);
header("Cache-Control: private, max-age=10800, pre-check=10800");
header("Pragma: private");
header("Expires: " . date(DATE_RFC822,strtotime(" 11 months")));
header('Content-type: image/png');
echo $img;
This results in the following image:
This only happens with a very small subset of the large library of similar icon images I have, and I cannot figure out why. Googling around I've found that some ImageMagick versions have issues with weird color profiles, but they all have the same color profile (sRGB), they're all the same dimensions, and while this image is greyscale it does not only happen to greyscale images, etc.
Even curiouser, it does not happen at all on my staging server, which runs the same the same version of php5-imagick (originally 3.2.1 but upgraded to 3.3.0RC2 in the hopes of making this problem go away). The only relevant difference I can find between the two servers is that when running phpinfo, the staging (unaffected) server says
Imagick compiled with ImageMagick version ImageMagick 6.8.9-9 Q16 x86_64 2015-01-05 http://www.imagemagick.org
Imagick using ImageMagick library version ImageMagick 6.8.9-9 Q16 x86_64 2015-09-19 http://www.imagemagick.org
while the production (affected) server says
Imagick compiled with ImageMagick version ImageMagick 6.7.7-10 2014-03-08 Q16 http://www.imagemagick.org
Imagick using ImageMagick library version ImageMagick 6.7.7-10 2014-03-08 Q16 http://www.imagemagick.org
To try to remedy this I've compiled and installed ImageMagick 6.9.2-5 on the production server from source. This has not affected the results of phpinfo which still reports 6.7.7-10, in spite of convert -version returning
Version: ImageMagick 6.9.2-5 Q16 x86_64 2015-11-02 http://www.imagemagick.org
I can't figure out how to point the imagick extension to the new ImageMagick binaries. And futher I actually have no idea if the version of ImageMagick is what's causing this effect, but I have run out of other ideas and it's the only difference I can find, so it's the rabbit hole I've been jumping down for the last few hours.
Is there a way to configure the ImageMagick path in php5-imagick? Or has anyone else experienced this weird effect on (some) images and successfully solved it in some other way?
Related
I have installed Imagick 3.4.4 in my WAMP using the steps defined here: https://newsinfo-blog.blogspot.com/2015/03/install-imagick-on-wamp-server.html
I then use the following code to convert a PDF to a JPEG image:
$im = new Imagick();
$im->setResolution(300,300);
$im->readImage($_SERVER['DOCUMENT_ROOT'] . '/codeigniter/assets/lofthouse.pdf[0]');
$im->setImageFormat('jpeg');
$im->writeImage('thumblofthouse.jpg');
$im->clear();
$im->destroy();
But I am getting the following error message :
An unknown error has occurred Type: ImagickException
Message: NoDecodeDelegateForThisImageFormat `PDF' #
error/constitute.c/ReadImage/509
What am i doing wrong? How can I save the first page of a PDF as an image?
I have noted that when I try :
print_r(Imagick::queryFormats());
the result is an empty array.
EDIT:
These are the steps I have undertaken so far:
Downloaded ImageMagick https://imagemagick.org/script/download.php#windows and installed it via the installer, put it in my D:\software folder.
Downloaded & installed Ghostscript : https://www.ghostscript.com/download/gsdnld.html , placed it in D:\ folder, and ticked the checkbox to generate the fonts.
Copied the php_imagick.dll file to my /ext/ folder
Copied over all the CORE_RL_* files to apache/bin/ folder
Added the root path to the installation directory of ImageMagick in my PATH variables (and put it way above the PHP line)
EDIT2:
I've also done the following steps, although i'm definitely not sure whether these are needed
Created a new system variable called MAGICK_HOME and let it point to the imagemagick root directory.
modified the policy.xml in ImageMagick by adding <policy domain="module" pattern="{PS,PDF,XPS}" rights="read|write"/> in the policymap attribute.
This is what phpinfo() returns:
imagick module enabled
imagick module version 3.4.4
imagick classes Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator, ImagickKernel
Imagick compiled with ImageMagick version ImageMagick 7.0.7-11 Q16 x86 2017-11-23 http://www.imagemagick.org
Imagick using ImageMagick library version ImageMagick 7.0.7-11 Q16 x86 2017-11-23 http://www.imagemagick.org
ImageMagick copyright Copyright (C) 1999-2015 ImageMagick Studio LLC
ImageMagick release date 2017-11-23
ImageMagick number of supported formats: 0
EDIT3: I am able to convert PDF to JPG via the commandline using ImageMagick. After all the steps above, i'm now getting the following error:
Type: ImagickException
Message: no decode delegate for this image format `PDF' # error/constitute.c/ReadImage/509
Same problem for me. Solved.
Check your file extension, be sure to have '.pdf'
Note : in my case ifpdf version is 1.4 or less, a bad or empty extension is not a problem, conversion will work, but for new pdf version i got exception "no delegated...".
I am reading in an SVG using RGB color scheme and converting to a JPG with CMYK using Imagick library in PHP. It was all working properly on my local machine and others, however when I deploy this to the server the colors get messed up (a blue color is getting much darker).
Below is my conversion code:
// start conversion to JPG
$image = new Imagick();
$image->setBackgroundColor(new ImagickPixel('white'));
$image->readImageBlob(file_get_contents('../assets/Map.svg'));
// finalize settings of the JPG
$image->transformImageColorspace(imagick::COLORSPACE_CMYK);
$image->setImageFormat("jpg");
$image->setImageCompressionQuality(100);
$image->setImageUnits(imagick::RESOLUTION_PIXELSPERINCH);
$image->setImageResolution(100, 100);
$filename = $company_id . '-Map.jpg';
$image->writeImage("../maps/" . $filename);
$image->clear();
$image->destroy();
The colors in the SVG are like the following: style="fill: #193B71;"
My first thought was related to the versions of the software and they seem to be very close though not identical:
Local Machine:
PHP 7.2.1
imagick module 3.4.3
ImageMagick 6.9.6-2 Q16 x86_64 2017-11-27
GPL Ghostscript 9.20 (2016-09-26)
Mac OS 10.11.6
Remote Server:
PHP 7.0.27
imagick module 3.4.1
ImageMagick 6.7.8-9 2016-06-16 Q16
GPL Ghostscript 9.20 (2016-09-26)
CentOS Linux release 7.2.1511 (Core)
I was wondering if the ImageMagick version is the issue here before going through the process of upgrading that on the server? Or if anyone had a suggestion of what else to check against as I'm not entirely familiar with all the tools the php imagick module might be using to make this conversion.
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 :)
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
I read all the questions before posting this .
I am trying to install ImageMagick on my local system Windows 7.It gets installed without But when i try using it to crop images I get NoDecodeDelegateForThisImageFormat .
I am running Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7
This is what i did
I installed ImageMagick ImageMagick-6.8.9-8-Q16-x86-dll.exe (I tried 6.8.1 and 6.7 also)
I got the dll from http://pecl.php.net/package/imagick/3.1.2/windows TS for PHP 5.4
Updated php.ini
The server started with out problem .
I checked via cmd the ImageMagick is working fine.
phpinfo() ImageMagick number of supported formats: 0
I tried many DLL's but none is working i need a solution to this .
Also phpinfo keeps on showing ImageMagick version:ImageMagick 6.8.8-4 Q16 x86 2014-01-29 even when i uninstalled it / updated it .
identify -version
Version: ImageMagick 6.8.9-8 Q16 x86 2014-08-26 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC Modules OpenMP
Delegates: bzlib cairo freetype jbig jng jp2 jpeg lcms lqr pangocairo png ps rsv
g tiff webp xml zlib
I am trying to open Jpg.
ImageMagick inside php is a really different from the standalone cmd version.
So, you need not only the php_imagic.dll connected to your php.ini.
But also the CORE_RL_*_.dll files in the Apache bin directory.
This will enable the readers.
Now you need the ENcoders. These are obtained from the standalone installation and located in [ImageMagick install dir]\modules\coders. Copy them to Apache's bin directory as well.
Now check the phpinfo();
The downside of this is that you need to match dll's from Standalone version to the one that is Compiled in the php-extension.