docksal / service-cli

CLI service image for Docksal
https://docksal.io
MIT License
19 stars 45 forks source link

Add SVG support to ImageMagick #147

Closed aczietlow closed 4 years ago

aczietlow commented 4 years ago

A quick fin exec 'identify -list format' or fin exec 'identify -version' will show that SVG is not supported by imagemagick on the CLI images.

We're using imagemagick for SVG to png conversion on a project hosted on Pantheon, which themselves has svg support through RSVG. https://pantheon.io/docs/external-libraries

lmakarov commented 4 years ago

On the latest docksal/cli images (base on Debian 10), installing the libmagickcore-6.q16-3-extra package does the trick.

docker@cli:/var/www$ sudo apt-get install libmagickcore-6.q16-3-extra
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'libmagickcore-6.q16-6-extra' instead of 'libmagickcore-6.q16-3-extra'
The following additional packages will be installed:
  fontconfig gsfonts libcairo2 libdatrie1 libdjvulibre-text libdjvulibre21 libfribidi0 libgraphite2-3 libharfbuzz0b libilmbase23 libjxr-tools libjxr0 libopenexr23 libpango-1.0-0
  libpangocairo-1.0-0 libpangoft2-1.0-0 libpixman-1-0 libthai-data libthai0 libwmf0.2-7 libxcb-render0 libxcb-shm0 libxrender1
Suggested packages:
  inkscape libwmf0.2-7-gtk
The following NEW packages will be installed:
  fontconfig gsfonts libcairo2 libdatrie1 libdjvulibre-text libdjvulibre21 libfribidi0 libgraphite2-3 libharfbuzz0b libilmbase23 libjxr-tools libjxr0 libmagickcore-6.q16-6-extra
  libopenexr23 libpango-1.0-0 libpangocairo-1.0-0 libpangoft2-1.0-0 libpixman-1-0 libthai-data libthai0 libwmf0.2-7 libxcb-render0 libxcb-shm0 libxrender1
0 upgraded, 24 newly installed, 0 to remove and 32 not upgraded.
Need to get 8,774 kB of archives.
After this operation, 19.0 MB of additional disk space will be used.
Do you want to continue? [Y/n] 

After that, SVG shows up in ImageMagick's supported formats list:

docker@cli:/var/www$ identify -list format | grep -i svg
     MSVG  SVG       rw+   ImageMagick's own SVG internal renderer
      SVG  SVG       rw+   Scalable Vector Graphics (XML 2.9.4)
     SVGZ  SVG       rw+   Compressed Scalable Vector Graphics (XML 2.9.4)

docker@cli:/var/www$ php -i | grep "ImageMagick supported formats" | grep -i svg
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, CMYK, CMYKA, CR2, CRW, CUR, CUT, DATA, DCM, DCR, DCX, DDS, DFONT, DJVU, DNG, DOT, DPX, DXT1, DXT5, EPDF, EPI, EPS, EPS2, EPS3, EPSF, EPSI, EPT, EPT2, EPT3, ERF, EXR, FAX, FILE, FITS, FRACTAL, FTP, FTS, G3, G4, GIF, GIF87, GRADIENT, GRAY, GRAYA, GROUP4, GV, H, HALD, HDR, HEIC, 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, MAGICK, 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, PGX, PICON, PICT, PIX, PJPEG, PLASMA, PNG, PNG00, PNG24, PNG32, PNG48, PNG64, PNG8, PNM, PPM, PREVIEW, PS, PS2, PS3, PSB, PSD, PTIF, PWP, RADIAL-GRADIENT, RAF, RAS, RAW, RGB, RGBA, RGBO, RGF, RLA, RLE, RMF, RW2, SCR, 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, WMZ, WPG, X, X3F, XBM, XC, XCF, XPM, XPS, XV, XWD, YCbCr, YCbCrA, YUV
lmakarov commented 4 years ago

Interestingly, identify -version still does not list SVG after installing libmagickcore-6.q16-3-extra:

docker@cli:/var/www$ identify -version
Version: ImageMagick 6.9.10-23 Q16 x86_64 20190101 https://imagemagick.org
Copyright: © 1999-2019 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC Modules OpenMP 
Delegates (built-in): bzlib djvu fftw fontconfig freetype heic jbig jng jp2 jpeg lcms lqr ltdl lzma openexr pangocairo png tiff webp wmf x xml zlib

@aczietlow can you validate on your end whether installing that package is sufficient?

aczietlow commented 4 years ago

@lmakarov That did the trick and is way easier than recompiling imagemagick. Thanks for that. What I've learned above all else is how unpleasant intense image manipulation can be for SVGs :D

Want me to update the PR to install the apt package?

lmakarov commented 4 years ago

There is an alternative PR #160 already in place. It also installs librsvg2-2 and librsvg2-bin, which adds A LOT (~200MB uncompressed) to the image size. We'll proceed with only installing libmagickcore-6.q16-3-extra. Thanks for confirming that that's sufficient for adding SVG support in imagemagick.

aczietlow commented 4 years ago

I believe that identify -list format show all the support file formats that imagemagick can process, where identify -version shows delegates, or other software it uses pass throughs to process. e.g. imagemagick needs a delegate to process RAW image files.