Is there a way to convert svg to png/jpeg in SilverStripe?

Silverstripe Version: SS4.13

Question:

I’m trying to set up on the fly conversion from inline svg (in template), to png / jpg image. I’ve tried using js and canvas for this, but get an incomplete result (missing fonts and clipPath images). I’ve also tried using php for this, but it requires Imagick. I have the extension installed for SilverStripe anyway, but how do I access Imagick functions through SilverStripe?

Any help would be much appreciated.

There’s no built-in functionality in Silverstripe CMS that would do this for you, no. Imagick can (sometimes, though apparently with varying results) handle it as you’ve noted, but the Intervention Image abstraction doesn’t expose that functionality.

If you want to use Imagick for this you’ll have to use it directly.

Alternatively you’ll need to find a third-party library to handle this for you if you need this functionality.

1 Like

Thanks. This is helpful to know. I’ve managed to get it working with js after a lot of fiddling - for anyone who comes across this problem in the future, it may be helpful to know that missing fonts and images work if they are base64 encoded.

To get base64 images in SilverStripe, check out the silverstripe-file-base64 module: