Converting dynamic svg to png with ImageMagick

How would you convert svg stored as a string to a png file using the command line ImageMagick with PHP?

Michael.

Not sure what format your original data is in but this works with a svg file:

magick svg_test.svg svg_result.jpg or convert svg_test.svg svg_result.jpg depending on your version

The svg is not written as a file but dynamically generated as a string.

There is an inline: method and I tried it a few years ago without success on some base 64 data. Having a look around I found a link to a base 64 example but if you look at the bottom of this section http://www.imagemagick.org/Usage/files/#inline there is an example without the base 64 part. It does not seem to be documented very well.

I was passing the base64 data via Ajax but can not remember how now - probably in a variable?

I know you specified command line but you might be able to do it with imagick and readblob.

OK, thank you. I think the easiest thing will be to write a php file that dynamically outputs an svg file. Then the regukar method should work.

Thanks for helping me think through this.

Michael

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.