ACJ
ACJ

Reputation: 2609

PHP ImageMagick returning incorrect content types

I have an image generator that allows me to generate different file formats (like JPEG, PNG, etc.) on the fly using Imagick::setImageType. This works like a charm on my old laptop and on a production server, but on a newer laptop that I started using, Imagick::getImageMimeType appears to not know what the correct MIME types for common image formats are, and returns image/x-png for PNG, image/x-gif for GIF, etc.

What’s curious to me, is that the content of the images that are generated (by echoing Imagick::getImageBlob) look just fine, which implies ImageMagick itself is working correctly. The only problem is that it sends these incorrect content type headers, which cause webbrowsers to download the image, rather than display it (except for the case of image/x-png, which browser happen to recognize as a legacy MIME type).

The only differencs with the other laptop I can think of is that this one is using newer software (PHP 7.4 on Windows 10 versus PHP 7.2 on Windows 7), but I fail to see how that would have anything to do with the mapping from image types to content types in ImageMagick.

Frankly, I have no idea where to start looking (googling didn’t help me much in this case), and I was wondering if anyone could point me in the right direction.

For what it’s worth, this is the relevant section from phpinfo() in the environment where it’s acting weird:

imagick module enabled
imagick module version 3.4.4
imagick classes Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator, ImagickKernel
Imagick compiled with ImageMagick version ImageMagick 7.0.7-11 Q16 x64 2017-11-23 http://www.imagemagick.org
Imagick using ImageMagick library version ImageMagick 7.0.7-11 Q16 x64 2017-11-23 http://www.imagemagick.org
ImageMagick copyright Copyright (C) 1999-2015 ImageMagick Studio LLC
ImageMagick release date 2017-11-23
ImageMagick number of supported formats: 238
ImageMagick supported formats 3FR, 3G2, 3GP, AAI, AI, ART, ARW, AVI, AVS, BGR, BGRA, BGRO, BIE, BMP, BMP2, BMP3, BRF, CAL, CALS, CANVAS, CAPTION, CIN, CIP, CLIP, CLIPBOARD, CMYK, CMYKA, CR2, CRW, CUR, CUT, DCM, DCR, DCX, DDS, DFONT, DJVU, DNG, DOT, DPS, DPX, DXT1, DXT5, EMF, EPDF, EPI, EPS, EPS2, EPS3, EPSF, EPSI, EPT, EPT2, EPT3, ERF, EXR, FAX, FILE, FITS, FLIF, FPX, FRACTAL, FTP, FTS, G3, G4, GIF, GIF87, GRADIENT, GRAY, GROUP4, GV, HALD, HDR, HISTOGRAM, HRZ, HTM, HTML, HTTP, HTTPS, ICB, ICO, ICON, IIQ, INFO, INLINE, IPL, ISOBRL, ISOBRL6, J2C, J2K, JBG, JBIG, JNG, JNX, JP2, JPC, JPE, JPEG, JPG, JPM, JPS, JPT, JSON, K25, KDC, LABEL, M2V, M4V, MAC, MAP, MASK, MAT, MATTE, MEF, MIFF, MKV, MNG, MONO, MOV, MP4, MPC, MPEG, MPG, MRW, MSL, MSVG, MTV, MVG, NEF, NRW, NULL, ORF, OTB, OTF, PAL, PALM, PAM, PANGO, PATTERN, PBM, PCD, PCDS, PCL, PCT, PCX, PDB, PDF, PDFA, PEF, PES, PFA, PFB, PFM, PGM, PICON, PICT, PIX, PJPEG, PLASMA, PNG, PNG00, PNG24, PNG32, PNG48, PNG64, PNG8, PNM, PPM, PS, PS2, PS3, PSB, PSD, PTIF, PWP, RADIAL-GRADIENT, RAF, RAS, RAW, RGB, RGBA, RGBO, RGF, RLA, RLE, RMF, RW2, SCR, SCREENSHOT, SCT, SFW, SGI, SHTML, SIX, SIXEL, SPARSE-COLOR, SR2, SRF, STEGANO, SUN, SVG, SVGZ, TEXT, TGA, THUMBNAIL, TIFF, TIFF64, TILE, TIM, TTC, TTF, TXT, UBRL, UBRL6, UIL, UYVY, VDA, VICAR, VID, VIFF, VIPS, VST, WBMP, WEBP, WMF, WMV, WPG, X3F, XBM, XC, XCF, XPM, XPS, XV, YCbCr, YCbCrA, YUV

Upvotes: 2

Views: 322

Answers (1)

ACJ
ACJ

Reputation: 2609

After trying out some random things, I found something that surprisingly works in this case. I installed the plain old ImageMagick Windows installer, and removed all the DLL mumbo-jumbo that all the online tutorials talk about (except for the php_imagick.dll in php/ext, of course).

So my setup is a lot simpler than it was before, and works better.

Upvotes: 1

Related Questions