Skip to content

Instantly share code, notes, and snippets.

@maxivak
Last active September 29, 2022 18:25
Show Gist options
  • Save maxivak/1476f7e979879da9f75371a86d5627b5 to your computer and use it in GitHub Desktop.
Save maxivak/1476f7e979879da9f75371a86d5627b5 to your computer and use it in GitHub Desktop.
Issue with Carrierwave, ImageMagick with processing svg files

Issue with Carrierwave, ImageMagick (or MiniMagick) with processing svg files

Problem:

When uploading svg file with Carrierwave you may get an error:

Failed to manipulate with MiniMagick, maybe it is not an image? 
Original Error: `identify /tmp/mini_magick20190222-32759-1g7lnmy.svg` failed with error:

or working with SVG files:

  • check in command line
identify -verbose myfile.svg

you may get this error:

Aborted (core dumped)

If you see an error, it means you installation of ImageMagick doesn't work properly with SVG files.

  • Make some checks

  • Check ImageMagick supports svg

To get a complete listing of which image formats are supported on your system, type

identify -list format

Associated with the SVG tag you will find the RSVG version #, e.g.

SVG SVG rw+ Scalable Vector Graphics (RSVG 2.22.2)
  • check
identify -list configure | grep svg

see

DISTCHECK_CONFIG_FLAGS  --disable-deprecated  --with-quantum-depth=16  --with-jemalloc=no  --with-umem=no  --with-autotrace=no  --with-gslib=no  --with-fontpath=  --with-rsvg=no  --with-perl=no 

!NOTE! see --with-rsvg=no which means that ImageMagick couldn't find rsvg in your system.

  • check
identify -list delegate | grep "svg =" 
       

see

svg =>          "rsvg-convert" -o "%o" "%i"
convert -list configure
  • ImageMagick and SVG

ImageMagick utilizes inkscape if its in your execution path otherwise RSVG. If neither are available, ImageMagick reverts to its internal SVG renderer.

ImageMagick with RSVG

  • install packages for RSVG
sudo apt-get install librsvg2-bin
  • check rsvg works
rsvg-convert my.svg > my.png
  • install imagemagick from sources

  • download

wget https://imagemagick.org/download/ImageMagick.tar.gz
  • untar
tar xvzf ImageMagick.tar.gz
  • configure with option --with-rsvg=yes !!!
cd ImageMagick-7.0.8
./configure --with-autotrace=no  --with-gslib=yes  --with-fontpath=  \
  --enable-delegate-build=yes  --enable-shared  --enable-static   --with-modules=yes \
  --without-perl --without-magick-plus-plus --disable-openmp \
  --with-bzlib=yes \
  --with-jpeg=yes \
  --with-png=yes \
  --with-tiff=yes \
  --with-xml=yes \
  --with-rsvg=yes   

you should see DELEGETAES like this:

    DELEGATES       = mpeg jng jpeg png x xml zlib

then

make
  • If ImageMagick configured and compiled without complaint, you are ready to install it on your system. install on your system:
sudo make install

sudo ldconfig /usr/local/lib

  • verify the ImageMagick install worked properly
/usr/local/bin/identify my.svg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment