Imagick无法加载图像,出现“NoDecodeDelegateForThisImageFormat”错误消息。

15

正在尝试创建缩略图,但我遇到了一些错误,而且对Imagick没有任何经验。

以下是我的PHP代码:

<?php
try {
    $imagick = new Imagick();
    $imagick->readImage('C:\xampp\htdocs\ppa\032.JPG');
    $imagick->thumbnailImage(800, 800);
    $imagick->writeImage('032(2).JPG');
}
catch(Exception $e) {
    die('Error when creating a thumbnail: ' . $e->getMessage());
}
?>

然后我得到了这个错误代码:

创建缩略图时出错:NoDecodeDelegateForThisImageFormat `C:\xampp\htdocs\ppa\032.JPG' @ error/constitute.c/ReadImage/555

这里有一些使用某些代码生成的信息,但我无法再次找到它...:/

Array
(
    [GD Version] => bundled (2.1.0 compatible)
    [FreeType Support] => 1
    [FreeType Linkage] => with freetype
    [T1Lib Support] => 
    [GIF Read Support] => 1
    [GIF Create Support] => 1
    [JPEG Support] => 1
    [PNG Support] => 1
    [WBMP Support] => 1
    [XPM Support] => 1
    [XBM Support] => 1
    [JIS-mapped Japanese Font Support] => 
)

文件信息:

enter image description here enter image description here

编辑:

1. I get the error instantly, there is no delay at all.
2. Running commands directly from CMD works on the examples given from installation instructions. 

I have just copied the wizard.jpg from the ImageMagick folder to use in the above script instead, just incase there is a problem with my image, but I get the same error. 

**Edit 2**

   Format  Mode  Description
------------------------------------------------------------------------------
      3FR  r--   Hasselblad CFV/H3D39II
        A* rw+   Raw alpha samples
      AAI* rw+   AAI Dune image
       AI  rw-   Adobe Illustrator CS2
      ART* rw-   PFS: 1st Publisher Clip Art
      ARW  r--   Sony Alpha Raw Image Format
      AVI  r--   Microsoft Audio/Visual Interleaved
      AVS* rw+   AVS X image
        B* rw+   Raw blue samples
      BGR* rw+   Raw blue, green, and red samples
     BGRA* rw+   Raw blue, green, red, and alpha samples
      BIE* rw-   Joint Bi-level Image experts Group interchange format (1.6)
      BMP* rw-   Microsoft Windows bitmap image
     BMP2* -w-   Microsoft Windows bitmap image (V2)
     BMP3* -w-   Microsoft Windows bitmap image (V3)
      BRF* -w-   BRF ASCII Braille format
        C* rw+   Raw cyan samples
      CAL* rw-   Continuous Acquisition and Life-cycle Support Type 1
           Specified in MIL-R-28002 and MIL-PRF-28002
     CALS* rw-   Continuous Acquisition and Life-cycle Support Type 1
           Specified in MIL-R-28002 and MIL-PRF-28002
   CANVAS* r--   Constant image uniform color
  CAPTION* r--   Caption
      CIN* rw-   Cineon Image File
      CIP* -w-   Cisco IP phone image format
     CLIP* rw+   Image Clip Mask
CLIPBOARD* rw-   The system clipboard
     CMYK* rw+   Raw cyan, magenta, yellow, and black samples
    CMYKA* rw+   Raw cyan, magenta, yellow, black, and alpha samples
      CR2  r--   Canon Digital Camera Raw Image Format
      CRW  r--   Canon Digital Camera Raw Image Format
      CUR* rw-   Microsoft icon
      CUT* r--   DR Halo
      DCM* r--   Digital Imaging and Communications in Medicine image
           DICOM is used by the medical community for images like X-rays.  The
           specification, "Digital Imaging and Communications in Medicine
           (DICOM)", is available at http://medical.nema.org/.  In particular,
           see part 5 which describes the image encoding (RLE, JPEG, JPEG-LS),
           and supplement 61 which adds JPEG-2000 encoding.
      DCR  r--   Kodak Digital Camera Raw Image File
      DCX* rw+   ZSoft IBM PC multi-page Paintbrush
      DDS* rw+   Microsoft DirectDraw Surface
    DFONT* r--   Multi-face font package (Freetype 2.5.3)
      DNG  r--   Digital Negative
      DPX* rw-   SMPTE 268M-2003 (DPX 2.0)
           Digital Moving Picture Exchange Bitmap, Version 2.0.
           See SMPTE 268M-2003 specification at http://www.smtpe.org

     DXT1* rw+   Microsoft DirectDraw Surface
     DXT5* rw+   Microsoft DirectDraw Surface
      EMF  r--   Windows Enhanced Meta File
     EPDF  rw-   Encapsulated Portable Document Format
      EPI  rw-   Encapsulated PostScript Interchange format
      EPS  rw-   Encapsulated PostScript
     EPS2* -w-   Level II Encapsulated PostScript
     EPS3* -w+   Level III Encapsulated PostScript
     EPSF  rw-   Encapsulated PostScript
     EPSI  rw-   Encapsulated PostScript Interchange format
      EPT  rw-   Encapsulated PostScript with TIFF preview
     EPT2  rw-   Encapsulated PostScript Level II with TIFF preview
     EPT3  rw+   Encapsulated PostScript Level III with TIFF preview
      ERF  r--   Epson RAW Format
      FAX* rw+   Group 3 FAX
           FAX machines use non-square pixels which are 1.5 times wider than
           they are tall but computer displays use square pixels, therefore
           FAX images may appear to be narrow unless they are explicitly
           resized using a geometry of "150x100%".

     FITS* rw-   Flexible Image Transport System
  FRACTAL* r--   Plasma fractal image
      FTS* rw-   Flexible Image Transport System
        G* rw+   Raw green samples
       G3* rw-   Group 3 FAX
      GIF* rw+   CompuServe graphics interchange format
    GIF87* rw-   CompuServe graphics interchange format (version 87a)
 GRADIENT* r--   Gradual linear passing from one shade to another
     GRAY* rw+   Raw gray samples
   GROUP4* rw-   Raw CCITT Group4
     HALD* r--   Identity Hald color lookup table image
      HDR* rw+   Radiance RGBE image format
HISTOGRAM* -w-   Histogram of the image
      HRZ* rw-   Slow Scan TeleVision
      HTM* -w-   Hypertext Markup Language and a client-side image map
     HTML* -w-   Hypertext Markup Language and a client-side image map
      ICB* rw-   Truevision Targa image
      ICO* rw+   Microsoft icon
     ICON* rw-   Microsoft icon
     INFO  -w+   The image format and characteristics
   INLINE* r--   Base64-encoded inline images
      IPL* rw+   IPL Image Sequence
   ISOBRL* -w-   ISO/TR 11548-1 format
      J2C* rw-   JPEG-2000 Code Stream Syntax (2.0.0)
      J2K* rw-   JPEG-2000 Code Stream Syntax (2.0.0)
      JBG* rw+   Joint Bi-level Image experts Group interchange format (1.6)
     JBIG* rw+   Joint Bi-level Image experts Group interchange format (1.6)
      JNG* rw-   JPEG Network Graphics
           See http://www.libpng.org/pub/mng/ for details about the JNG
           format.
      JNX* r--   Garmin tile format
      JP2* rw-   JPEG-2000 File Format Syntax (2.0.0)
      JPC* rw-   JPEG-2000 Code Stream Syntax (2.0.0)
     JPEG* rw-   Joint Photographic Experts Group JFIF format (80)
      JPG* rw-   Joint Photographic Experts Group JFIF format (80)
      JPT* rw-   JPEG-2000 File Format Syntax (2.0.0)
     JSON  -w+   The image format and characteristics
        K* rw+   Raw black samples
      K25  r--   Kodak Digital Camera Raw Image Format
      KDC  r--   Kodak Digital Camera Raw Image Format
    LABEL* r--   Image label
        M* rw+   Raw magenta samples
      M2V  rw+   MPEG Video Stream
      M4V  rw+   Raw MPEG-4 Video
      MAC* r--   MAC Paint
      MAP* rw-   Colormap intensities and indices
     MASK* rw+   Image Clip Mask
      MAT  rw+   MATLAB level 5 image format
    MATTE* -w+   MATTE format
      MEF  r--   Mamiya Raw Image File
     MIFF* rw+   Magick Image File Format
      MNG* rw+   Multiple-image Network Graphics (libpng 1.6.10)
           See http://www.libpng.org/pub/mng/ for details about the MNG
           format.
     MONO* rw-   Raw bi-level bitmap
      MOV  rw+   MPEG Video Stream
      MP4  rw+   MPEG-4 Video Stream
      MPC* rw+   Magick Persistent Cache image format
     MPEG  rw+   MPEG Video Stream
      MPG  rw+   MPEG Video Stream
      MRW  r--   Sony (Minolta) Raw Image File
      MSL* rw+   Magick Scripting Language
     MSVG  rw+   ImageMagick's own SVG internal renderer
      MTV* rw+   MTV Raytracing image format
      MVG* rw-   Magick Vector Graphics
      NEF  r--   Nikon Digital SLR Camera Raw Image File
      NRW  r--   Nikon Digital SLR Camera Raw Image File
     NULL* rw-   Constant image of uniform color
        O* rw+   Raw opacity samples
      ORF  r--   Olympus Digital Camera Raw Image File
      OTB* rw-   On-the-air bitmap
      OTF* r--   Open Type font (Freetype 2.5.3)
      PAL* rw-   16bit/pixel interleaved YUV
     PALM* rw+   Palm pixmap
      PAM* rw+   Common 2-dimensional bitmap format
    PANGO* r--   Pango Markup Language (Pangocairo 1.36.0)
  PATTERN* r--   Predefined pattern
      PBM* rw+   Portable bitmap format (black and white)
      PCD* rw-   Photo CD
     PCDS* rw-   Photo CD
      PCL  rw+   Printer Control Language
      PCT* rw-   Apple Macintosh QuickDraw/PICT
      PCX* rw-   ZSoft IBM PC Paintbrush
      PDB* rw+   Palm Database ImageViewer Format
      PDF  rw+   Portable Document Format
     PDFA  rw+   Portable Document Archive Format
      PEF  r--   Pentax Electronic File
      PES* r--   Embrid Embroidery Format
      PFA* r--   Postscript Type 1 font (ASCII) (Freetype 2.5.3)
      PFB* r--   Postscript Type 1 font (binary) (Freetype 2.5.3)
      PFM* rw+   Portable float format
      PGM* rw+   Portable graymap format (gray scale)
    PICON* rw-   Personal Icon
     PICT* rw-   Apple Macintosh QuickDraw/PICT
      PIX* r--   Alias/Wavefront RLE image format
    PJPEG* rw-   Joint Photographic Experts Group JFIF format (80)
   PLASMA* r--   Plasma fractal image
      PNG* rw-   Portable Network Graphics (libpng 1.6.10)
           See http://www.libpng.org/ for details about the PNG format.
    PNG00* rw-   PNG inheriting bit-depth and color-type from original
    PNG24* rw-   opaque or binary transparent 24-bit RGB (zlib 1.2.7)
    PNG32* rw-   opaque or transparent 32-bit RGBA
    PNG48* rw-   opaque or binary transparent 48-bit RGB
    PNG64* rw-   opaque or transparent 64-bit RGBA
     PNG8* rw-   8-bit indexed with optional binary transparency
      PNM* rw+   Portable anymap
      PPM* rw+   Portable pixmap format (color)
  PREVIEW* -w-   Show a preview an image enhancement, effect, or f/x
       PS  rw+   PostScript
      PS2* -w+   Level II PostScript
      PS3* -w+   Level III PostScript
      PSB* rw+   Adobe Large Document Format
      PSD* rw+   Adobe Photoshop bitmap
     PTIF* rw+   Pyramid encoded TIFF
      PWP* r--   Seattle Film Works
        R* rw+   Raw red samples
RADIAL-GRADIENT* r--   Gradual radial passing from one shade to another
      RAF  r--   Fuji CCD-RAW Graphic File
      RAS* rw+   SUN Rasterfile
      RGB* rw+   Raw red, green, and blue samples
     RGBA* rw+   Raw red, green, blue, and alpha samples
     RGBO* rw+   Raw red, green, blue, and opacity samples
      RGF* rw-   LEGO Mindstorms EV3 Robot Graphic Format (black and white)
      RLA* r--   Alias/Wavefront image
      RLE* r--   Utah Run length encoded image
      RMF  r--   Raw Media Format
      RW2  r--   Panasonic Lumix Raw Image
      SCR* r--   ZX-Spectrum SCREEN$
      SCT* r--   Scitex HandShake
      SFW* r--   Seattle Film Works
      SGI* rw+   Irix RGB image
    SHTML* -w-   Hypertext Markup Language and a client-side image map
SPARSE-COLOR* -w+   Sparse Color
      SR2  r--   Sony Raw Format 2
      SRF  r--   Sony Raw Format
  STEGANO* r--   Steganographic image
      SUN* rw+   SUN Rasterfile
      SVG  rw+   Scalable Vector Graphics (RSVG 2.40.1)
     SVGZ  rw+   Compressed Scalable Vector Graphics (RSVG 2.40.1)
     TEXT* rw+   Text
      TGA* rw-   Truevision Targa image
THUMBNAIL* -w+   EXIF Profile Thumbnail
     TIFF* rw+   Tagged Image File Format (LIBTIFF, Version 4.0.3)
   TIFF64* rw-   Tagged Image File Format (64-bit) (LIBTIFF, Version 4.0.3)
     TILE* r--   Tile image with a texture
      TIM* r--   PSX TIM
      TTC* r--   TrueType font collection (Freetype 2.5.3)
      TTF* r--   TrueType font (Freetype 2.5.3)
      TXT* rw+   Text
     UBRL* -w-   Unicode Text format
      UIL* -w-   X-Motif UIL table
     UYVY* rw-   16bit/pixel interleaved YUV
      VDA* rw-   Truevision Targa image
    VICAR* rw-   VICAR rasterfile format
      VID* rw+   Visual Image Directory
     VIFF* rw+   Khoros Visualization image
      VST* rw-   Truevision Targa image
     WBMP* rw-   Wireless Bitmap (level 0) image
     WEBP* rw-   WebP Image Format (libwebp 0.3.1)
      WMF  r--   Windows Meta File
      WMV  rw+   Windows Media Video
      WPG* r--   Word Perfect Graphics
      X3F  r--   Sigma Camera RAW Picture File
      XBM* rw-   X Windows system bitmap (black and white)
       XC* r--   Constant image uniform color
      XCF* r--   GIMP image
      XPM* rw-   X Windows system pixmap (color)
      XPS  r--   Microsoft XML Paper Specification
       XV* rw+   Khoros Visualization image
        Y* rw+   Raw yellow samples
    YCbCr* rw+   Raw Y, Cb, and Cr samples
   YCbCrA* rw+   Raw Y, Cb, Cr, and alpha samples
      YUV* rw-   CCIR 601 4:1:1 or 4:2:2

* native blob support
r read support
w write support
+ support for multiple images

编辑3

C:\Users\Martyn Ball>identify "C:/xampp/htdocs/ppa/wizard.jpg"

C:/xampp/htdocs/ppa/wizard.jpg JPEG格式,大小为265x352像素,采用8位sRGB色彩模式,文件大小为68.3KB,运行时间为0.000秒,总用时0.017秒。

编辑4

代码运行:

<?php
print_r(Imagick::queryFormats());
?>

结果:

数组()

编辑5 我使用他们网站上的普通安装程序(32位)安装了Imagick,然后我终于找到了一个可行的dll,因为ImageMagick的网站上并没有可靠的DLL下载部分。

这是phpinfo()显示的关于Imagick的内容。 enter image description here

编辑6 我阅读了以下网站,并在此列出推荐和我所做的事情。

  1. 如果您下载DLL,请确保它与Apache和PHP编译使用的Visual Studio版本相同(PHP 5.5可能是VC11)
  2. 根据您的设置下载线程安全或非线程安全的DLL
  3. 将DLL复制到扩展文件夹中
  4. 在php.ini中启用扩展
  5. 下载并安装ImageMagick,确保选择带有动态链接库的版本,还要确保它建立在与PHP和Apache(32/64位)相同的平台上,即使你有一个64位系统,像我一样,你也可能会运行32位版本的PHP和Apache
  6. 将ImageMagick路径添加到系统PATH变量中,安装程序可以为您完成此操作,但请在高级系统设置中检查它是否存在
  7. 重启Apache
  8. 检查php_info(),看看扩展是否已启用,并且支持某些图像格式

我的结果 1. 下载:ImageMagick-6.8.8-9-Q16-x86-dll.exe - 在安装目录中找到名为“php_imagick.dll”的dll文件,并将其放入C:/xampp/php/ext/

这导致出现以下错误: httpd.exe - Entry Point Not Found The procedure entry point MagickGetImageAttribute could not be located in the dynamic link library CORE_RL_wand_.dll.

还有这个错误: PHP Startup: Unable to load dynamic library 'C:\xampp\php\ext\php_imagick.dll' - The specified procedure could not be found. 2. N/A 3. 复制到C:/xampp/php/ext/ 4. 启用扩展:extension=php_imagick.dll 5. 再次下载此版本(我有32位PHP):ImageMagick-6.8.8-9-Q16-x86-dll.exe (每像素16位的Win32动态) 6.enter image description here

  1. 如上所述,现在出现了错误,在之前没有,但可能是错误的dll。

还尝试了以下方法,但仍然出现相同的错误: extension=C:/ImageMagick/php_imagick.dll

ImageMagick已安装在C:/ImageMagick中。

答案:

看起来我可能在使用错误版本的dll文件,与我的PHP和Apache版本不匹配。我下载了以下文件,并将扩展链接更改为ImageMagick的安装文件夹,而不是将dll文件移动到php文件夹中。

ImageMagick-6.6.5-10-Q8-windows-dll.exe

PHP 5.5.9。

Apache 2.4.7。


2
相对路径并不意味着“相对于这个PHP脚本”,而是相对于“当前工作目录”,这可以被各种情况改变。您应该始终引用完整路径;魔术常量__DIR__指的是文件所在的目录。 - IMSoP
好的,既然这是一个不同的错误信息,那就是完全不同的问题。你确定引用的图像是有效的JPEG格式了吗? - IMSoP
我已经在我的帖子@IMSoP的底部添加了文件信息。 - Martyn Ball
这里是否也适用于 https://www.mediawiki.org/wiki/Thread:Project:Support_desk/ImageMagick_Thumbnail_error:_%22no_decode_delegate%22;_%22no_data_returned%22? - Mike 'Pomax' Kamermans
1
可能相关的是关于DLL的部分 http://hexydec.com/blog/how-to-get-imagemagick-working/ - Danack
显示剩余16条评论
4个回答

11

我认为你使用的Image Magick库版本不支持你尝试打开的图片格式。你可以通过运行以下命令来测试:

identify -list format

查看是否列出了JPEG 2000或JP2。

编辑

问题的提问者更新了Image Magick列出的图像格式列表,这似乎是一个完整的列表。然而,在PHP中运行Imagick::queryFormats()显示没有支持的图像格式。

当您使用不正确版本的Image Magick DLL时,这显然是一个常见问题,与您安装的PHP版本不匹配。Imagick将声称已经无错误地加载,但是既不能加载也不能保存任何图像。


我已经更新了我的帖子,其中展示了@Danack的结果。 - Martyn Ball
JPC* rw- JPEG-2000 Code Stream Syntax (2.0.0) - Martyn Ball
1
我在哪里可以找到兼容的PHP和Imagick API以及Imagick版本列表? - Timo Huovinen
4
我们在哪里可以找到兼容的 PHP 和 Imagick DLLs 及 Imagick 版本列表? - Positivity

11

虽然这个问题比较老,但是由于现在看起来有些棘手,所以我分享一个快速解决方案:

如果你使用的是Windows系统,在这里可以找到包含ImageMagick DLL文件的软件库。

在成功加载/php/ext/文件夹下的php_imagick.dll扩展之后,

  1. 打印一个phpinfo()页面,并查看对应的ImageMagick版本,它会出现在'Imagick using ImageMagick library version'标签下面。
  2. 然后下载该版本的ImageMagick的zip文件,例如最新的TS-VC11-x86稳定版本:
    php_imagick v3.4.1 > ImageMagick-6.9.3-7-vc11-x86.zip
  3. 最后,解压下载的zip文件,进入其bin文件夹,并复制所有IM_MOD_RL_...dll文件和FILTER_...dll文件到/apache/bin/文件夹,然后重新启动服务器即可完成!
    无需运行安装程序或更改环境变量等。

太好了,谢谢。我也不得不对我的php ext目录做同样的操作,但还要复制ImageMagickObject.dll。 - thydzik
它适用于php 7.1.1,Xampp,Windows 10。存储库url为.zip,提取并复制到/apache/bin文件夹中即可。即使我已经在设置了环境变量的系统中安装了它,它也不能像以前那样工作。 - Felix Aballi

1

看起来我可能一直在使用错误版本的dll文件,与我的PHP和Apache版本不匹配。我下载了以下文件,并将扩展链接更改为ImageMagick的安装文件夹,而不是将dll文件移动到php文件夹中。

ImageMagick-6.6.5-10-Q8-windows-dll.exe

PHP 5.5.9.

Apache 2.4.7.


0
即使安装了GhostScript,我们在从AWS切换到Azure后仍无法让imagick代码工作,出现了Delegate错误。最终我们将PHP代码转换为Image Magick命令行,使用execInBackground函数运行该命令(PHP.net Exec() Page)。
注意:仅使用exec命令行无法正常终止php脚本。
//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);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接