ImageMagick : ImageCoderSignatureMismatch `miff' - php

I've updated my version of ImageMagick and its bindings for PHP.
I've installed ImageMagick-7.0.4-9-Q16-x64,
and php_imagick-3.4.3-7.0-nts-vc14-x64,
running on PHP 7.0.10.
The command-line seems to work well since I've managed to execute a simple magick convert image.png -resize 50% imageSmall.png successfully.
The problem is that a PHP script who ran successfully on ImageMagick 6.8.x (I don't remember very well), but can't do it with this version.
It gave me the following error :
ImageCoderSignatureMismatch `miff': 210 != 610 # error/module.c/OpenModule/1342
Sometimes it shows me Unable to set the image format instead, I don't really know why.
I've found where in my code this error was triggered :
public function init(){
var_dump('begin init fcrender canvas');
if($this->_canvas == null){
$this->_canvas = new Imagick();
/////// It's the following line :
$this->_canvas->newImage($this->_width, $this->_height, 'transparent', 'miff');
/////////////////////////////////
$this->_filename = 'image';
$this->_extension = 'png';
}
}
So why does this error come from ? Thanks you for your help ! :)

This means that the wrong module was loaded. The 210 != 610 are the version signature of the miff module, so IM 7 is expected miff 610, but IM 6's 210 was loaded.
A couple options to fix.
Uninstall all ImageMagick 6 resources.
Reinstall ImageMagick 7 to an isolated location, and use $MAGICK_HOME environment variable.
Define MAGICK_CODER_MODULE_PATH environment variable to correct module path.
More info # Resources documentation.

I think php_imagick is simply not compatible with ImageMagick7.x.x.
I downloaded and installed ImageMagick6.9.3 that I found here : http://windows.php.net/downloads/pecl/deps/
(To install, I simply the folder in C:\imagemagick\ and put the content of "bin\" at the top-level, in C:\imagemagick\.
Then I copied all the CORE_RL_*.dll in C:\wamp64\bin\apache\apache2.4.23\bin\ .)
This works perfectly in PHP 7.0.10 with imagick3.4.3 downloadable here : https://pecl.php.net/package/imagick
Thank you for your help guys !

Related

Cannot convert PDF to JPG using ImageMagick and GhostScript

I'm trying to convert a pdf on my local computer to a jpg file and then using Tesseract to read the image text. Simply testing code like this:
$pdf = new Pdf('C:\testing\test.pdf');
$pdf->saveImage('C:\testing\test.jpg');
$tess = new TesseractOCR('C:\testing\test.jpg');
$myresults = $tess->run();
$this->vars['result'] = $myresults;
Produces the following error:
PDFDelegateFailed `The system cannot find the file specified. ' # error/pdf.c/ReadPDFImage/794
I am using the following for my scenario:
OctoberCMS/Laravel
PHP 7.2.34 64 bit
Ghostscript 9.53.3 64 bit (32 bit didn't work either)
ImageMagick 7.0.7-11 Q16 x64
Xampp
Windows 10 64 bit
When I try converting a jpg to a png, ImageMagick works fine, but as soon as I try a PDF, I get the error. I have looked and tried solutions with little luck. I know the issue is most likely Ghostscript, as many have reported that it's the one that gives the most headaches on Windows 10, but I have no idea where to even begin trying to connect it to ImageMagick.
Any help, please?
Well, I did end up finding a workaround for this. Instead of using ImageMagick with Ghostscript, I ended up just using Ghostscript on its own. The conversion works flawlessly without issues.

How to set library_path in config for ImageMagick library which is installed in windows machine

I'm getting the following error while I try to crop an image using ImageMagick
library:
Image processing failed. Please verify that your server supports the chosen protocol and that the path to your image library is correct
So the library is installed on my windows machine in program files(x 86) folder.
I have set the config like this:-
$config['image_library'] = 'ImageMagick';<br>
$config['library_path'] = 'C:\\ImageMagick\\Program Files (x86)\\';
I'm setting the $config['library_path'] wrong and please note that the environment variable is as follows:-
path : -- C:\Program Files (x86)\ImageMagick
As pointed out by #fmw42 - check your version of ImageMagick, and the command your image_lib.php is executing.
The image_process_imagemagick() function in my version of Codeigniter tries to execute convert command. In ImageMagick 7, this should be magick.
Ideally, update your CI version (I presume this is fixed in newer versions).
A quicker workaround, not to be advised, is to edit the $this->library_path var in image_process_imagemagick() method to read magick, instead of convert
if ( ! preg_match('/magick/i', $this->library_path))
{
$this->library_path = rtrim($this->library_path, '/').'/magick';
}

Cannot make Imagick detect supported format on Windows + PHP 5.6 (Xampp)

its been 3 days of research, google and frustration to make imagick work on my XAMPP box. I can get as far on making it as php module. But it cannot detect supported formats.
As you can see, I currently have 3.1.2 installed, but I actually worked all the way from the most recent 3.4.1 and jumping from those releases tagged with stable but I just can't make it work.
When I try to run:
<?php
$handle = fopen('http://xxxxx.png', 'rb');
$img = new Imagick();
$img->readImageFile($handle);
$img->thumbnailImage(100, 0);
echo $image;
I am getting:
Uncaught exception 'ImagickException' with message 'Unable to read image from the filehandle' in xxxxx:5 Stack trace: #0 xxxxx\index.php(5): Imagick->readimagefile(Resource id #3) #1 {main} thrown in xxxxx\index.php on line 5
What I have is:
Windows 8.1 64-bit
PHP 5.6.12, x86, TS
(http://i.imgur.com/2pnneqO.png)
This is what I actually have done so far, in terms of installing it:
Download any -Thread Safe (TS) x86 package from
https://pecl.php.net/package/imagick
Extract the .zip (1) php_imagick.dll to C:\_XAMPP\php\ext (2)
Extract CORE_RL_* files to C:\_xampp\apache\bin
Download ImageMagick-7.0.1-1-Q16-x86-dll.exe from
Link
Installed it at C:\ImageMagick
Add MAGICK_HOME to environment PATH. http://i.imgur.com/jQAWl3W.png
All *_.dll file in C:\ImageMagick\modules\coders copy to
C:\_Xampp\apache\bin
All *_.dll file in C:\ImageMagick\modules\coders copy to
C:\ImageMagick\
Restart Apache via Xampp
And still can't make my PHP detect Imagick supported file formats even though they should be http://prntscr.com/b1l54u :((
Can somebody tell me what did I miss? Please?
You seem to be going a bit of a convoluted route.
The method I used to install it when I had it running was:
Download and install Ghostscript with an exe file
Download and install imagemagick with an exe file - make sure you let it add the path to the environmental variables. You may not need this step but I wanted to use Imagemagick I'm my website and on my computer anyway.
Download the Imagick dll file and put it in the recommended folder - I can not remember which now.
Uncomment the Imagick option in the php.ini file. I had
two or three php.ini files on my system and I did it in each one.
Turned off the computer and restarted. Started XAMPP and it worked.
This only worked for a couple of installs and when I upgraded the operating system I could not get it to work due to incompatible versions of php and the Imagick.dll. If I should ever want to use Imagick I would do it on my server as the hosts installed it there for me.
You can still write your code locally and test it on your production server. It is a bit of a pain but would probably be quicker/easier than trying to get Imagick working on your PC.
Out of interest I gave up with it and use Imagemagick with exec() and the command line.

PHP-Imagick on OSX, ImagickException: NoDecodeDelegateForThisImageFormat `/my-path/file.jpg' # error/constitute.c/ReadImage/550

My environment is: MacOSX 10.8.3, PHP 5.3.17, ImageMagick 6.8.0, Apache 2.2.22
I have installed ImageMagick and PHP-Imagick module by using macports.
ImageMagick works as expected, for example I can convert a JPG to GIF by using the console command convert /my-path/file.jpg file.gif.
However when I create a new Imagick instance by using a sample code as follow:
<?php
$m = new Imagick('/my-path/file.jpg');
I get the exception:
NoDecodeDelegateForThisImageFormat `/my-path/file.jpg' #
error/constitute.c/ReadImage/550
The format of the file doesnt change the result; I tested different JPG, GIF and PNG images however same exception occurs.
So I suspect, the PHP/Apache - ImageMagick integration part is somewhat faulty.
I saw this post on SO and applied the given resolution (adding the environment variable "MAGICKCODERMODULE_PATH" with the value "/opt/local/lib/ImageMagick-6.8.0/modules-Q16/coders") however that didn't make sense for my case. (I confirmed the existence of this environment variable from my phpinfo)
Outputs of some commands on my system:
identify -list format: http://pastebin.com/tiE7Jr1m
identify -list configure: http://pastebin.com/Zt8yiRhj
I will appreciate any suggestion.
Solution
chmod 755 /opt
Insight and Thoughts
At last. I managed to solve the problem.
As there were no answers and suggestions on SO; I'm not suprised that something not expected was causing it!..
#sathia suggested to define an environment variable to call ImageMagick binaries. However in my case, I need to use phpImagick extension and access ImageMagick through its API, so this suggestion didn't make sense.
But I wanted to give it a try and call ImageMagick's convert binary by using PHP's system function. After calling it, I got a return value of "126"; and 126 means, binary is found however it's not executable!..
I checked the binary in /opt/local/bin/convert and it has appropriate execute permissions, then I checked /opt/local/bin and /opt/local directories as well and they were executable too. However the catch was /opt folder's permission was 700!
I managed to execute chmod 755 /opt and magically error has gone.
I've been there too, this is how I solved it:
<?php
define("IMAGE_MAGICK_PATH","/usr/local/bin/");
$in = '/my-path/file.jpg';
$out = '/my-path/file.gif';
$convertString = IMAGE_MAGICK_PATH." convert ".$yourfile." ".$out;
exec($convertString);
hope it helps

Imagick not working

I am working on creating thumbnail image from the first page of pdf file. I almost tired every solution available on the web to make ImageMagick running but I still get the following error
Fatal error: Class 'Imagick' not found in C:\wamp\www\mediabox\application\controllers\cron.php on line 153
what I have done so far.
Installed GPL Ghostscript
Installed ImageMagick-6.7.6-Q16
Downloaded and copied the php_imagick.dll file in ext folder of my php installation.
Added extension=php_imagick.dll line to my php.ini file.
Restarted the apache server and windows many times :)
I am using codeigniter framework.
Php 5.3.10, apache 2.2.21, mysql 5.5.20, wamp 2.2 and win 7
On my localhost page in the loaded extensions category 'Imagemagick is not listed'
The code I have written is as
$image = explode('.', $filename_new);
$image_name = 'files/import/' . $ftp_upload["path"] ."/". $image[0] .".jpg";
//exec("convert -colorspace RGB -geometry 300x400! -density 200 " .$pdf_file."[0] ". $image_name);
$img = $image[0].".jpg" ;
$im = new Imagick($img);
$im->pingImage($img);
$im->readImage($img);
$im->thumbnailImage(100, null);
$im->writeImage( 'files/import/' . $ftp_upload["path"] ."/".$img);
$im->destroy();
The exec command create images but it is very slow I want to create thumbnail images using Imagick class and I hope it will be faster as compared to exec and convert thingy.
Any ideas what should I do to make the Imagick class available for my php ?
Thanks
I am not sure where you got your binaries from, but it seemed like something I experienced about a month ago. Some of the binaries I tried would show up in phpinfo(), but refused to work, whereas others wouldn't even show in phpinfo().
I then just went ahead and compiled my own binaries as per my question here.
I just went and compiled those binaries for you. They are for x86, compiled with VC9 and there are threadsafe and non-threadsafe versions. The version is 3.1.0RC1 (latest).
You can download them here: http://min.us/mtg0Z66BI
Let me know if it works for you :)
On my server the pecl-imagick extension only works with mod_mpm_prefork - it does not work with mod_mpm_worker.so or mod_mpm_event.so
That may be your issue.
If you are only creating jpg add the jpg hint to the exec( ) command which will be faster than Imagick.
Use -define jpeg:size=200x200 before reading the image in - 200x200 is the output image size.
I suspect Imagick is not installed correctly

Categories