3

I have read about converting SVG images to PNG and I tried a bit, but Imagick doesn't seem to cut it. Does Imagick have some problems with Gaussian blur and/or using it on groups?

Is there another way to resize (before converting it) and convert an SVG to PNG or whatever in PHP?

Here's my SVG (mostly self written, except for the path, which was exported from Gimp): http://dt4.my1xt.tk/pi2.svg

And this is Imagick's result: http://dt4.my1xt.tk/pi-im.png

so as it should be visible enough Imagick won't cut it. I cannot really change the server configuration, but maybe PHP can run some binaries that I could put there (no idea, never tried that)?

Edit: rescale can be done with some str_replace() magic with the size of the SVG (without forgetting to set a viewbox in the svg before). Now the problem remains that I need another method for PNG-ing the SVG.

halfer
  • 19,824
  • 17
  • 99
  • 186
My1
  • 475
  • 5
  • 21
  • What is "the SVG->PNG thing"? – halfer Jul 21 '15 at 22:26
  • When you say "without ImageMagick", do you mean you do not have access to either the `Imagick` extension _and_ the `convert` command? Most Unix-like hosts have access to the latter, through `exec()` etc. – halfer Jul 21 '15 at 22:27
  • 1
    `xvfb-run phantomjs rasterize.js http://dt4.my1xt.tk/pi2.svg pi2.png`, in PHP use `system()` or `exec()` command. Require `phantomjs` installed with `xvfb` – Alvin K. Jul 21 '15 at 22:52
  • @Halfer SVG is pretty nice and all but it isnt compatible with everything (and renderng seems to take half an eternity on mobile firefox as example), so I wanna use some PHP to convert it into a PNG file which is widely supported and so, but I wanna do it dynamically so I dont have to do this for each size everytime... also I said that Imagick doesnt really wield good results (as the png shows and it became worse when I started to use the tag – My1 Jul 22 '15 at 23:23
  • @Alvin is there a quick way to check whether that stuff is installed or not? – My1 Jul 22 '15 at 23:26
  • 2
    OK. If you don't like ImageMagick, consider [Inkscape instead](http://stackoverflow.com/a/9570081/472495). It renders very nicely from the console. – halfer Jul 22 '15 at 23:45
  • 1
    maybe useful [Convert SVG image to PNG with PHP](http://stackoverflow.com/questions/4809194/convert-svg-image-to-png-with-php)? – Ryan Vincent Jul 22 '15 at 23:49
  • @halfer not like, you are funny, the point is that it doesnt render correctly what you can see by comparison of the svg with a rendered result, the result example is a bit old since I fiddled a lot in the SVG to make it more "php-usable" including styles and resizes of that logo and stuff. also with that inkscape thing I essentally only need exec("command") also another question can this thing run like "portable" so it doesnt actually need to be installed on the server but de facto just the binary somewhere where I can access it? would make stuff A LOT easier – My1 Jul 23 '15 at 00:45
  • oops character limit... in the end I dont wanna save but rather a direct output so i could essentially just (for example, where the p switch does some resizing that already works, but I cant really get a png out, yet) – My1 Jul 23 '15 at 00:47
  • 1
    @My1 This answers your question [How to Check If Shell Command Exists](http://stackoverflow.com/questions/12424787/how-to-check-if-a-shell-command-exists-from-php) – Alvin K. Jul 23 '15 at 05:01
  • Hmm, I don't think I understand the tone of your replies. What what it I said that you did not like? My advice has been helpful thus far. – halfer Jul 23 '15 at 08:26
  • I dont say your advice wasnt helpful but you said "OK. If you don't like ImageMagick, consider Inkscape instead." but I just wanted to explain that it's not that I dont like imagick, but that this tool plainly doesnt work as it should. but can inkscape direct output the image without saving it, like as data string or alike? – My1 Jul 23 '15 at 09:29
  • so Inkscape is a nice solution if you have it on the server and sufficient rights on the server and it works splendidly. – My1 Sep 11 '15 at 10:50

0 Answers0