Trying to create a thumbnail, but i\'m getting some errors and I have no experience with Imagick.
Here is my PHP:
It seems I may have been using the wrong version of the dll for my PHP and Apache version. I downloaded the following file, and changed the extension link to the install folder of ImageMagick instead of moving the dll t the php folder.
ImageMagick-6.6.5-10-Q8-windows-dll.exe
PHP 5.5.9.
Apache 2.4.7.
I think your version of the underlying Image Magick library is running without support for the image format that you're trying to open. You should be able to test this by running:
identify -list format
And seeing if JPEG 2000 or JP2 is listed.
EDIT
The OP updated with the list of image formats listed by Image Magick and it seemed a complete list of formats. However running Imagick::queryFormats()
in PHP shows that no image formats are supported.
This apparently is a common problem when you are using a version of the Image Magick DLL that is not the correct version for your installed PHP version. Imagick will claim to be loaded without errors, but there will be no image formats available for either loading or saving images.
Even after installing GhostScript, we could not get the imagick code to work after switching from AWS to Azure, getting the Delegate error. We ended up converting the PHP code to Image Magick command line, using the function execInBackground to run the command (PHP.net Exec() Page)
NOTE: The command line did not work using exec alone. The php script would not terminate normally.
//from PHP.net
function execInBackground($cmd) {
if (substr(php_uname(), 0, 7) == "Windows"){
pclose(popen("start /B ". $cmd, "r"));
}
else {
exec($cmd . " > /dev/null &");
}
}
//create a thumbnail from the first page of PDF
//old php code
/*
$image_magick = new imagick();
$image_magick->setbackgroundcolor('white');
$image_magick->readImage($file_path . "[0]");
$image_magick = $image_magick->flattenImages();
$image_magick->setResolution(300,300);
$image_magick->thumbnailImage(102, 102, true);
$image_magick->setImageFormat('jpg');
$image_magick->writeImage($thumbnail_path);
*/
//command line syntax
$cmd = "magick convert " . chr(34) . $file_path . "[0]" . chr(34) . " -background white -flatten -resample " . chr(34) . "300x300" . chr(34) . " -thumbnail " . chr(34) . "102x102" . chr(34) . " -format jpg -write " . chr(34) . $thumbnail_path . chr(34);
execInBackground($cmd);
Question is old but since this issue seems a bit hacky to solve also nowadays, I post here a quick solution:
If you're on Windows, you can find here a repository containing ImageMagick DLL.
After you successfully load php_imagick.dll
extension in /php/ext/
folder
phpinfo()
page and watch the corresponding ImageMagick version reported under
'Imagick using ImageMagick library version' labelbin
folder and copy all IM_MOD_RL_...dll
files and FILTER_...dll
files to /apache/bin/
folder, then restart your server, finish!