Search code examples
phpsvgpngjpeg

Convert JPG/PNG to SVG format using PHP


How do I convert JPG/PNG to SVG using PHP?

I know that it will not be vectorised, but I need it in a SVG-format.

I dont want to use any other software than PHP.

Something like this:

<?php

$image_to_cenvert = 'image.jpg';

$content = file_get_contents($image_to_cenvert);

$svg_file = fopen('image.svg','w+');

fputs($svg_file,$content);
fclose($svg_file);

?>

Solution

  • As i know your only chance to achieve that is to use imagick library but the format available depend on the settings so if you're on a shared server could not be possible do it.

    http://php.net/manual/en/book.imagick.php

    and here : Convert SVG image to PNG with PHP

    you can find an example on how to convert a SVG image to png, what you will need to do is given the oossibility of your imagick library to create and manipulate svg file adapt the script in the link over...