我对 ImageMagick
有疑问。我搜索了很多,但没有找到解决方案。我的问题与输出到 JPEG XR
格式有关。我正在尝试在 Windows 10
和 Linux Debian 9
服务器上的 PHP 7.0/7.1
中执行此操作。
我的代码:
<?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 应用:
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
和 JxrEncApp.exe
可从任何目录获取!
Linux 软件包:
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
...
Windows 上的 fatal error :
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
Linux 上的 fatal error :
Unable to set image format
维基 ImageMagick:
支持的图像格式:
JXR | RW | JPEG extended range | Requires the jxrlib delegate library. Put the JxrDecApp and JxrEncApp applications in your execution path. Read more this
变更日志:
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.
更新
echo $_SERVER['PATH'];
来自 Windows 上的 PHP:
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\nodejs\;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
目录:
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'];
来自 Linux 上的 PHP:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
执行自:
root@Server:~# which JxrEncApp
/usr/bin/JxrEncApp
root@Server:~# which JxrDecApp
/usr/bin/JxrDecApp
问题:
如何添加对 JXR 图片格式的支持?
最佳答案
好消息! Imagick 支持 JXR 或 JPEG Extended Range 格式,但不是以您希望的方式支持。您当前尝试访问它的方式是通过使用字节数组。 Magick.NET(Imagick .NET 库)的维护者在 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.
因此支持 JXR 格式,但不是以您希望的方式应用它。但是,可以按照 StackOverflow 中所述通过命令行完成转换 here或者像这样。
convert input.jpg jxr:output.jpg
剩下的就是编写一个执行此命令的脚本来为您进行转换。确保您正确保护该脚本及其输入和输出。祝你好运!
来源:
关于php - Imagick PHP 扩展无法输出 JPEG XR 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47279769/