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.
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'm running xampp on macOS (10.12.6) and installed Imagemagick (ImageMagick 7.0.7-3 Q16 x86_64 2017-09-19 ).
With the installed php Imagick extension, I can convert in php images from jpeg to png without problems.
But when I want to convert from tiff to png/jpeg, it doesnt work with the Imagick extension. But it works in terminal and the Imagemagick tiff DELEGATE is supported.
When I look at phpinfo(), there's no tiff support listed.
the PHP error is:
Uncaught ImagickException: unable to load module
'/usr/local/Cellar/imagemagick/7.0.7-3/lib/ImageMagick//modules-Q16HDRI/coders/tiff.la':
file not found # error/module.c/OpenModule/1270
Is the problem the double-backslash in the path?
When I navigate in the finder to the path with doubleback-backslash removed, there is the correct file.
I found the solution among the answers to issue #3919 for Homebrew on GitHub.
Try recompiling php-imagick71 and imagemagick one or several times in different order.
brew reinstall -s php-imagick71
brew reinstall -s imagemagick
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'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?
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