0

I have tried to convert SVG to PNG image but it's not working, Tested using this link, but it's creating the white image and if I used

$image->setBackgroundColor(new ImagickPixel('transparent')); it created the black/transparent image

SVG image : SVG image actual view on browser After converting: SVG to PNG

SVG with mask : Sample

Puneet
  • 5
  • 6
  • Check it - https://stackoverflow.com/questions/4809194/convert-svg-image-to-png-with-php – Dmitry Leiko Nov 29 '19 at 08:23
  • I have also tried the above code, it didn't work with external image, In my case assets folder having the custom image with mask image: – Puneet Nov 29 '19 at 08:48
  • Post a link to your actual SVG file. – fmw42 Nov 29 '19 at 17:03
  • I have added the my sample SVG file – Puneet Dec 02 '19 at 06:39
  • @fmw42 could you please guide me more here ? – Puneet Dec 26 '19 at 08:18
  • Your SVG file has a linked image, which cannot be found. It is linked to a local file at `assets/right.inside.mask.print.png` for the mask. If that file is not available, then it won't rasterize properly. – fmw42 Dec 26 '19 at 17:32
  • Thanks for reply @fmw42 Yes both mask and image files are in assets folder with SVG file, does this means I need to give site URL with mask and custom image Please see the sample file with assests folder and try to open in browser for better understanding – Puneet Dec 31 '19 at 09:54

1 Answers1

0

Given all your data downloaded to my computer, I can convert it to png using ImageMagick 6.9.10.82 Q16 Mac OSX Sierra that calls Inkscape 0.92.4 as the SVG renderer.

convert right.inside.svg x.png


enter image description here

You have not shown the correct result. So I do not know if this is correct or not. But it does appear to be correct given the images in the assets folder.

However, the mask and other image needs to be accessible from whomever is trying to view the svg file. So either the data needs to be downloaded or perhaps you need to provide the URL to those files on some server that has the svg file.

fmw42
  • 46,825
  • 10
  • 62
  • 80
  • I am able to convert the SVG to PNG also SVG to PDF **thanks you** @fmw42 I have installed the inkScape on my server and it's working now: https://connectwww.com/how-to-install-inkscape-on-ubuntu-best-vector-graphics-editor/5581/ – Puneet Jan 23 '20 at 11:30