Uncaught exception 'ImagickException'

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
kelfas
Posts: 5
Joined: 2016-02-25T01:01:21-07:00
Authentication code: 1151

Uncaught exception 'ImagickException'

Post by kelfas »

Hello,

I'm currently facing a problem when trying to convert a PDF to JPEG. I've installed ImageMagick, GhostScript and also imagick extension for PHP but I'm still getting the error:

Fatal error: Uncaught exception 'ImagickException'

My code is the following:

Code: Select all

$pdfFile = '/tmp/RE220216_01.pdf';
$imgFile = '/tmp/RE220216_01.jpeg';

$im = new Imagick();
$im->readimage($pdfFile);
$im->setResolution(72,72);
$im->setImageCompression(Imagick::COMPRESSION_JPEG);                
$im->setImageCompressionQuality(82);
$im->stripImage();
$im->setImageFormat('jpeg');
$im->writeImage($imgFile);
$im->clear();
$im->destroy();
Last edited by kelfas on 2016-02-25T12:54:14-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Uncaught exception 'ImagickException'

Post by snibgo »

You should first find where the failure occurs.

If the failure is that Ghostscript is not successfully called, then try setting the full path to Ghostscript in your delegates.xml file.
snibgo's IM pages: im.snibgo.com
kelfas
Posts: 5
Joined: 2016-02-25T01:01:21-07:00
Authentication code: 1151

Re: Uncaught exception 'ImagickException'

Post by kelfas »

Hello,

Thanks for your answer. The exceptions raises whe trying to set the image format to JPEG. I can't find this delegates.xml file. I'm working on CentOS. Does this file from ImageMagick configure.xml tells you something:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuremap [
<!ELEMENT configuremap (configure)+>
<!ELEMENT configure (#PCDATA)>
<!ATTLIST configure name CDATA #REQUIRED>
<!ATTLIST configure value CDATA #REQUIRED>
]>
<configuremap>
  <configure name="NAME" value="ImageMagick"/>
  <configure name="VERSION" value="6.7.3"/>
  <configure name="LIB_VERSION" value="0x673"/>
  <configure name="LIB_VERSION_NUMBER" value="6,7,3,9"/>
  <configure name="SVN_REVISION" value="6092" />
  <configure name="RELEASE_DATE" value="2011-11-27"/>
  <configure name="CONFIGURE" value="./configure "/>
  <configure name="PREFIX" value="/usr/local"/>
  <configure name="EXEC-PREFIX" value="/usr/local"/>
  <configure name="INCLUDE_PATH" value="/usr/local/include/ImageMagick"/>
  <configure name="CONFIGURE_PATH" value="/usr/local/etc/ImageMagick/"/>
  <configure name="SHARE_PATH" value="/usr/local/share/ImageMagick-6.7.3"/>
  <configure name="DOCUMENTATION_PATH" value="/usr/local/share/doc/ImageMagick/"/>
  <configure name="EXECUTABLE_PATH" value="/usr/local/bin"/>
  <configure name="LIBRARY_PATH" value="/usr/local/lib/ImageMagick-6.7.3"/>
  <configure name="CODER_PATH" value="/usr/local/lib/ImageMagick-6.7.3/modules-Q16/coders"/>
  <configure name="FILTER_PATH" value="/usr/local/lib/ImageMagick-6.7.3/modules-Q16/filters"/>
  <configure name="CC" value="gcc -std=gnu99 -std=gnu99"/>
  <configure name="CFLAGS" value="-fopenmp -g -O2 -Wall -pthread"/>
  <configure name="CPPFLAGS" value="-I/usr/local/include/ImageMagick"/>
  <configure name="PCFLAGS" value="-fopenmp"/>
  <configure name="DEFS" value="-DHAVE_CONFIG_H"/>
  <configure name="LDFLAGS" value="-L/usr/local/lib "/>
  <configure name="LIBS" value="-lMagickCore -lm -lgomp -lpthread "/>
  <configure name="CXX" value="g++"/>
  <configure name="CXXFLAGS" value="-pthread"/>
  <configure name="DISTCHECK_CONFIG_FLAGS" value="--disable-deprecated --with-quantum-depth=16 --with-umem=no --with-autotrace=no --with-fontconfig=no --with-gslib=no --with-fontpath= --with-pango=no --with-rsvg=no --with-xml=no --with-perl=no"/>
  <configure name="TARGET_CPU" value="x86_64"/>
  <configure name="TARGET_VENDOR" value="unknown"/>
  <configure name="TARGET_OS" value="linux-gnu"/>
  <configure name="HOST" value="x86_64-unknown-linux-gnu"/>
  <configure name="FEATURES" value="OpenMP "/>
  <configure name="DELEGATES" value=""/>
  <configure name="COPYRIGHT" value="Copyright (C) 1999-2011 ImageMagick Studio LLC"/>
  <configure name="WEBSITE" value="http://www.imagemagick.org"/>
  <configure name="QuantumDepth" value="16"/>
</configuremap>
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Uncaught exception 'ImagickException'

Post by fmw42 »

What do you get from

Code: Select all

convert -list configure
Does it list jpeg?

What versions of JPG do you get from

Code: Select all

convert -list format?
kelfas
Posts: 5
Joined: 2016-02-25T01:01:21-07:00
Authentication code: 1151

Re: Uncaught exception 'ImagickException'

Post by kelfas »

Hello,

Code: Select all

convert-list configure
output:

Code: Select all

Path: /usr/local/lib/ImageMagick-6.7.3/config/configure.xml

Name          Value
-------------------------------------------------------------------------------
CC            gcc -std=gnu99 -std=gnu99
CFLAGS        -fopenmp -g -O2 -Wall -pthread
CODER_PATH    /usr/local/lib/ImageMagick-6.7.3/modules-Q16/coders
CONFIGURE     ./configure 
CONFIGURE_PATH /usr/local/etc/ImageMagick/
COPYRIGHT     Copyright (C) 1999-2011 ImageMagick Studio LLC
CPPFLAGS      -I/usr/local/include/ImageMagick
CXX           g++
CXXFLAGS      -pthread
DEFS          -DHAVE_CONFIG_H
DELEGATES     
DISTCHECK_CONFIG_FLAGS --disable-deprecated --with-quantum-depth=16 --with-umem=no --with-autotrace=no --with-fontconfig=no --with-gslib=no --with-fontpath= --with-pango=no --with-rsvg=no --with-xml=no --with-perl=no
DOCUMENTATION_PATH /usr/local/share/doc/ImageMagick/
EXEC-PREFIX   /usr/local
EXECUTABLE_PATH /usr/local/bin
FEATURES      OpenMP 
FILTER_PATH   /usr/local/lib/ImageMagick-6.7.3/modules-Q16/filters
HOST          x86_64-unknown-linux-gnu
INCLUDE_PATH  /usr/local/include/ImageMagick
LDFLAGS       -L/usr/local/lib 
LIB_VERSION   0x673
LIB_VERSION_NUMBER 6,7,3,9
LIBRARY_PATH  /usr/local/lib/ImageMagick-6.7.3
LIBS          -lMagickCore -lm -lgomp -lpthread 
NAME          ImageMagick
PCFLAGS       -fopenmp
PREFIX        /usr/local
QuantumDepth  16
RELEASE_DATE  2011-11-27
SHARE_PATH    /usr/local/share/ImageMagick-6.7.3
SVN_REVISION  6092
TARGET_CPU    x86_64
TARGET_OS     linux-gnu
TARGET_VENDOR unknown
VERSION       6.7.3
WEBSITE       http://www.imagemagick.org

Path: [built-in]

Name          Value
-------------------------------------------------------------------------------
NAME          ImageMagick

Code: Select all

convert -list format
output:

Code: Select all

Format  Module    Mode  Description
-------------------------------------------------------------------------------
      3FR  DNG       r--   Hasselblad CFV/H3D39II
        A* RAW       rw+   Raw alpha samples
      AAI* AAI       rw+   AAI Dune image
       AI  PDF       rw-   Adobe Illustrator CS2
      ART* ART       rw-   PFS: 1st Publisher Clip Art
      ARW  DNG       r--   Sony Alpha Raw Image Format
      AVI  MPEG      r--   Microsoft Audio/Visual Interleaved
      AVS* AVS       rw+   AVS X image
        B* RAW       rw+   Raw blue samples
      BMP* BMP       rw-   Microsoft Windows bitmap image
     BMP2* BMP       -w-   Microsoft Windows bitmap image (V2)
     BMP3* BMP       -w-   Microsoft Windows bitmap image (V3)
        C* RAW       rw+   Raw cyan samples
      CAL* CALS      r--   Continuous Acquisition and Life-cycle Support Type 1
           Specified in MIL-R-28002 and MIL-PRF-28002
     CALS* CALS      r--   Continuous Acquisition and Life-cycle Support Type 1
           Specified in MIL-R-28002 and MIL-PRF-28002
   CANVAS* XC        r--   Constant image uniform color
  CAPTION* CAPTION   r--   Caption
      CIN* CIN       rw-   Cineon Image File
      CIP* CIP       -w-   Cisco IP phone image format
     CLIP* CLIP      -w+   Image Clip Mask
     CMYK* CMYK      rw+   Raw cyan, magenta, yellow, and black samples
    CMYKA* CMYK      rw+   Raw cyan, magenta, yellow, black, and alpha samples
      CR2  DNG       r--   Canon Digital Camera Raw Image Format
      CRW  DNG       r--   Canon Digital Camera Raw Image Format
      CUR* CUR       rw-   Microsoft icon
      CUT* CUT       r--   DR Halo
      DCM* 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  DNG       r--   Kodak Digital Camera Raw Image File
      DCX* PCX       rw+   ZSoft IBM PC multi-page Paintbrush
      DDS* DDS       r--   Microsoft DirectDraw Surface
    DFONT* TTF       ---   Multi-face font package
      DNG  DNG       r--   Digital Negative
      DPX* 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
           
     EPDF  PDF       rw-   Encapsulated Portable Document Format
      EPI  PS        rw-   Encapsulated PostScript Interchange format
      EPS  PS        rw-   Encapsulated PostScript
     EPS2* PS2       -w-   Level II Encapsulated PostScript
     EPS3* PS3       -w+   Level III Encapsulated PostScript
     EPSF  PS        rw-   Encapsulated PostScript
     EPSI  PS        rw-   Encapsulated PostScript Interchange format
      ERF  DNG       r--   Epson RAW Format
      FAX* 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* FITS      rw-   Flexible Image Transport System
  FRACTAL* PLASMA    r--   Plasma fractal image
      FTS* FTS       rw-   Flexible Image Transport System
        G* RAW       rw+   Raw green samples
       G3* FAX       rw-   Group 3 FAX
      GIF* GIF       rw+   CompuServe graphics interchange format
    GIF87* GIF       rw-   CompuServe graphics interchange format (version 87a)
 GRADIENT* GRADIENT  r--   Gradual linear passing from one shade to another
     GRAY* GRAY      rw+   Raw gray samples
     HALD*           r--   Identity Hald color lookup table image
      HDR* HDR       rw+   Radiance RGBE image format
HISTOGRAM* HISTOGRAM -w-   Histogram of the image
      HRZ* HRZ       rw-   Slow Scan TeleVision
      HTM* HTML      -w-   Hypertext Markup Language and a client-side image map
     HTML* HTML      -w-   Hypertext Markup Language and a client-side image map
      ICB* TGA       rw-   Truevision Targa image
      ICO* ICON      rw+   Microsoft icon
     ICON* ICON      rw-   Microsoft icon
     INFO  INFO      -w+   The image format and characteristics
   INLINE* INLINE    r--   Base64-encoded inline images
      IPL* IPL       rw+   IPL Image Sequence
        K* RAW       rw+   Raw black samples
      K25  DNG       r--   Kodak Digital Camera Raw Image Format
      KDC  DNG       r--   Kodak Digital Camera Raw Image Format
    LABEL* LABEL     r--   Image label
        M* RAW       rw+   Raw magenta samples
      M2V  MPEG      rw+   MPEG Video Stream
      M4V  MPEG      rw+   Raw MPEG-4 Video
      MAC* MAC       r--   MAC Paint
      MAP* MAP       rw-   Colormap intensities and indices
      MAT  MAT       rw+   MATLAB level 5 image format
    MATTE* MATTE     -w+   MATTE format
     MIFF* MIFF      rw+   Magick Image File Format
     MONO* MONO      rw-   Raw bi-level bitmap
      MOV  MPEG      rw+   MPEG Video Stream
      MP4  MPEG      rw+   MPEG-4 Video Stream
      MPC* MPC       rw+   Magick Persistent Cache image format
     MPEG  MPEG      rw+   MPEG Video Stream
      MPG  MPEG      rw+   MPEG Video Stream
      MRW  DNG       r--   Sony (Minolta) Raw Image File
      MSL* MSL       ---   Magick Scripting Language
     MSVG  SVG       -w+   ImageMagick's own SVG internal renderer
      MTV* MTV       rw+   MTV Raytracing image format
      MVG* MVG       rw-   Magick Vector Graphics
      NEF  DNG       r--   Nikon Digital SLR Camera Raw Image File
     NULL* NULL      rw-   Constant image of uniform color
        O* RAW       rw+   Raw opacity samples
      ORF  DNG       r--   Olympus Digital Camera Raw Image File
      OTB* OTB       rw-   On-the-air bitmap
      OTF* TTF       ---   Open Type font
      PAL* UYVY      rw-   16bit/pixel interleaved YUV
     PALM* PALM      rw+   Palm pixmap
      PAM* PNM       rw+   Common 2-dimensional bitmap format
  PATTERN* PATTERN   r--   Predefined pattern
      PBM* PNM       rw+   Portable bitmap format (black and white)
      PCD* PCD       rw-   Photo CD
     PCDS* PCD       rw-   Photo CD
      PCL  PCL       rw+   Printer Control Language
      PCT* PICT      rw-   Apple Macintosh QuickDraw/PICT
      PCX* PCX       rw-   ZSoft IBM PC Paintbrush
      PDB* PDB       rw+   Palm Database ImageViewer Format
      PDF  PDF       rw+   Portable Document Format
     PDFA  PDF       rw+   Portable Document Archive Format
      PEF  DNG       r--   Pentax Electronic File
      PES* PES       r--   Embrid Embroidery Format
      PFA* TTF       ---   Postscript Type 1 font (ASCII)
      PFB* TTF       ---   Postscript Type 1 font (binary)
      PFM* PFM       rw+   Portable float format
      PGM* PNM       rw+   Portable graymap format (gray scale)
    PICON* XPM       rw-   Personal Icon
     PICT* PICT      rw-   Apple Macintosh QuickDraw/PICT
      PIX* PIX       r--   Alias/Wavefront RLE image format
   PLASMA* PLASMA    r--   Plasma fractal image
      PNM* PNM       rw+   Portable anymap
      PPM* PNM       rw+   Portable pixmap format (color)
  PREVIEW* PREVIEW   -w-   Show a preview an image enhancement, effect, or f/x
       PS  PS        rw+   PostScript
      PS2* PS2       -w+   Level II PostScript
      PS3* PS3       -w+   Level III PostScript
      PSB* PSD       rw+   Adobe Large Document Format
      PSD* PSD       rw+   Adobe Photoshop bitmap
      PWP* PWP       r--   Seattle Film Works
        R* RAW       rw+   Raw red samples
RADIAL-GRADIENT* GRADIENT  r--   Gradual radial passing from one shade to another
      RAF  DNG       r--   Fuji CCD-RAW Graphic File
      RAS* SUN       rw+   SUN Rasterfile
      RGB* RGB       rw+   Raw red, green, and blue samples
     RGBA* RGB       rw+   Raw red, green, blue, and alpha samples
     RGBO* RGB       rw+   Raw red, green, blue, and opacity samples
      RLA* RLA       r--   Alias/Wavefront image
      RLE* RLE       r--   Utah Run length encoded image
      SCR* SCR       r--   ZX-Spectrum SCREEN$
      SCT* SCT       r--   Scitex HandShake
      SFW* SFW       r--   Seattle Film Works
      SGI* SGI       rw+   Irix RGB image
    SHTML* HTML      -w-   Hypertext Markup Language and a client-side image map
      SR2  DNG       r--   Sony Raw Format 2
      SRF  DNG       r--   Sony Raw Format
  STEGANO* STEGANO   r--   Steganographic image
      SUN* SUN       rw+   SUN Rasterfile
      SVG  SVG       -w+   Scalable Vector Graphics
     SVGZ  SVG       -w+   Compressed Scalable Vector Graphics
     TEXT* TXT       rw+   Text
      TGA* TGA       rw-   Truevision Targa image
THUMBNAIL* THUMBNAIL -w+   EXIF Profile Thumbnail
     TILE* TILE      r--   Tile image with a texture
      TIM* TIM       r--   PSX TIM
      TTC* TTF       ---   TrueType font collection
      TTF* TTF       ---   TrueType font
      TXT* TXT       rw+   Text
      UIL* UIL       -w-   X-Motif UIL table
     UYVY* UYVY      rw-   16bit/pixel interleaved YUV
      VDA* TGA       rw-   Truevision Targa image
    VICAR* VICAR     rw-   VICAR rasterfile format
      VID* VID       rw+   Visual Image Directory
     VIFF* VIFF      rw+   Khoros Visualization image
      VST* TGA       rw-   Truevision Targa image
     WBMP* WBMP      rw-   Wireless Bitmap (level 0) image
      WMV  MPEG      rw+   Windows Media Video
      WPG* WPG       r--   Word Perfect Graphics
      X3F  DNG       r--   Sigma Camera RAW Picture File
      XBM* XBM       rw-   X Windows system bitmap (black and white)
       XC* XC        r--   Constant image uniform color
      XCF* XCF       r--   GIMP image
      XPM* XPM       rw-   X Windows system pixmap (color)
      XPS  XPS       r--   Microsoft XML Paper Specification
       XV* VIFF      rw+   Khoros Visualization image
        Y* RAW       rw+   Raw yellow samples
    YCbCr* YCbCr     rw+   Raw Y, Cb, and Cr samples
   YCbCrA* YCbCr     rw+   Raw Y, Cb, Cr, and alpha samples
      YUV* YUV       rw-   CCIR 601 4:1:1 or 4:2:2

* native blob support
r read support
w write support
+ support for multiple images
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Uncaught exception 'ImagickException'

Post by fmw42 »

You have no delegates such as JPG, PNG, TIFF installed. How did you install Imagemagick? If from binary, then something is wrong? If from source, then you must install all the desired delegates before installing Imagemagick.

What do you get from

gs --version
kelfas
Posts: 5
Joined: 2016-02-25T01:01:21-07:00
Authentication code: 1151

Re: Uncaught exception 'ImagickException'

Post by kelfas »

Hello,

Thanks for your reply. I believe it was installed from source. Would it be solved if i reinstall ImageMagick using:

Code: Select all

yum install ImageMagick
The command:

Code: Select all

gs --version
outputs:

Code: Select all

9.04
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Uncaught exception 'ImagickException'

Post by fmw42 »

Sorry, I am not an expert on installing on Unix. If you can, try installing from binary. See http://www.imagemagick.org/script/binary-releases.php.

GS 9.04 is a bit old also.
kelfas
Posts: 5
Joined: 2016-02-25T01:01:21-07:00
Authentication code: 1151

Re: Uncaught exception 'ImagickException'

Post by kelfas »

It turned out that the server had two ImageMagick installations. The one installed from source didn't have the delegates for JPG. Luckily I've found the source so I was able to uninstall it running:

Code: Select all

make uninstall
Then, I reinstall it and also reinstall imagick. Both from sources.

Thank you very much.
Post Reply