I have a problem with ImageMagick
. I searched a lot, but failed to find the solution. My problem has to do with output to JPEG XR
format. I'm trying to do this in PHP 7.0/7.1
on Windows 10
and Linux Debian 9
server.
My code:
<?php
if (TRUE !== extension_loaded('imagick')) {
throw new Exception('Imagick extension is not loaded.');
}
$image = new Imagick();
$image->newImage(100, 100, new ImagickPixel('red'));
// $image->setImageFormat('jpg'); // <-- It works
$image->setImageFormat('jxr'); // <-- Fatal error: Uncaught ImagickException: UnableToOpenModuleFile
header("Content-Type: image/" . $image->getImageFormat());
echo $image;
$image->destroy();
Windows app:
C:\Users\Andrei>JxrDecApp.exe
JPEG XR Decoder Utility
Copyright 2013 Microsoft Corporation - All Rights Reserved
...
C:\Users\Andrei>JxrEncApp.exe
JPEG XR Encoder Utility
Copyright 2013 Microsoft Corporation - All Rights Reserved
...
JxrDecApp.exe
and JxrEncApp.exe
available from any directory!
Linux packages:
root@Server:~# dpkg-query -l | grep jxr
ii libjxr-tools 1.1-6+b1 amd64 JPEG-XR lib - command line apps
ii libjxr0:amd64 1.1-6+b1 amd64 JPEG-XR lib - libraries
root@Server:~# dpkg-query -l | grep imagick
ii php-imagick 3.4.3~rc2-2 amd64 Provides a wrapper to the ImageMagick library
root@Server:~# JxrDecApp
JPEG XR Decoder Utility
Copyright 2013 Microsoft Corporation - All Rights Reserved
...
root@Server:~# JxrEncApp
JPEG XR Encoder Utility
Copyright 2013 Microsoft Corporation - All Rights Reserved
...
Fatal error on Windows:
Uncaught ImagickException: UnableToOpenModuleFile `C:\WINDOWS\system32\config\systemprofile\AppData\Local\ImageMagick\IM_MOD_RL_jxr_.dll': No such file or directory @ warning/module.c/GetMagickModulePath/830 in D:\www\temp\jxr\index.php on line 11
Fatal error on Linux:
Unable to set image format
Wiki ImageMagick:
Supported Image Formats:
JXR | RW | JPEG extended range | Requires the jxrlib delegate library. Put the JxrDecApp and JxrEncApp applications in your execution path. Read more this
ChangeLog:
2013-04-29 6.8.5-3 Cristy
Add DeleteImageArtifact() for jpeg:extent artifact (thanks to Jimmy Xie @ Microsoft).
Add support for JXR / WDP image format.
Update
echo $_SERVER['PATH'];
from PHP on Windows:
c:\Program Files\ImageMagick-6.9.3-7-vc14-x64\bin\;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Program Files\Microsoft MPI\Bin\;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\130\DTS\Binn\;C:\Program Files\Microsoft SQL Server\130\DTS\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\;C:\Program Files\Git\cmd;C:\Program Files (x86)\GtkSharp\2.12\bin;C:\Program Files\Java\JDK18~1.0_1\bin;C:\Program Files\JetBrains\IntelliJ IDEA 2017.2.1\plugins\maven\lib\maven3\bin;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files
odejs\;C:\Program Files\JetBrains\IntelliJ IDEA 2017.2.1\bin\;C:\Program Files (x86)\Skype\Phone\;C:\WINDOWS\system32\config\systemprofile\AppData\Local\Microsoft\WindowsApps
dir:
C:\Users\Andrei>dir "c:\Program Files\ImageMagick-6.9.3-7-vc14-x64\bin\*jxr*"
11.11.2017 22:53 464 896 JXRDecApp.exe
11.11.2017 22:53 469 504 JXREncApp.exe
echo $_SERVER['PATH'];
from PHP on Linux:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
execute from:
root@Server:~# which JxrEncApp
/usr/bin/JxrEncApp
root@Server:~# which JxrDecApp
/usr/bin/JxrDecApp
Question:
How to add support for JXR image format?
Good news! The JXR or JPEG Extended Range format is supported by Imagick but not in the way you want it to. How you are currently try to access it is through the use of a byte array. The maintainer of Magick.NET (Imagick .NET library) states the following in a closed issue on Github:
The format is supported but you will need to do some 'magick' to make it work. Reading JXR files will only work when you copy the file JXRDecApp.exe to your bin directory and read from a file on disk that has a .jxr extension. Reading from a byte array is not supported. It would be nice if the code of the jxrlib project (http://jxrlib.codeplex.com) could be part of ImageMagick. Maybe I should create an issue for this in the ImageMagick project. You will need to compile JXRDecApp.exe yourself because there are no binaries available.
So the JXR format is supported but not in the way you want to apply it. However, the conversion can be done through command line as described on StackOverflow here or like this.
convert input.jpg jxr:output.jpg
What remains is to write a script that executes this command to do the conversion for you. Make sure you properly secure that script and it's input and output. Good luck!
Source:
Some PHP packages come with their own Imagick package rather than using the system package. You might then find as a result what is supported on the command line and what PHP supports differs.
In the source PHP directly gets the list of supported formats from Imagick itself.
If it's not different versions, perhaps there is some hidden abstraction where jxr is an alias for another parent format with some specific options.