I've been researching and testing implementations in repositories, but I have not been able to apply it to my case. I would like to know is there any native way of doing this, considering that the svg file is stored in a folder on my server. I tried using Imagick as follows:
<?php
$im = new Imagick();
try {
$im->setBackgroundColor(new ImagickPixel("transparent"));
$svg = '<svg aria-hidden="true" data-prefix="fas" data-icon="address-book" class="svg-inline--fa fa-address-book fa-w-14" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path fill="currentColor" d="M436 160c6.6 0 12-5.4 12-12v-40c0-6.6-5.4-12-12-12h-20V48c0-26.5-21.5-48-48-48H48C21.5 0 0 21.5 0 48v416c0 26.5 21.5 48 48 48h320c26.5 0 48-21.5 48-48v-48h20c6.6 0 12-5.4 12-12v-40c0-6.6-5.4-12-12-12h-20v-64h20c6.6 0 12-5.4 12-12v-40c0-6.6-5.4-12-12-12h-20v-64h20zm-228-32c35.3 0 64 28.7 64 64s-28.7 64-64 64-64-28.7-64-64 28.7-64 64-64zm112 236.8c0 10.6-10 19.2-22.4 19.2H118.4C106 384 96 375.4 96 364.8v-19.2c0-31.8 30.1-57.6 67.2-57.6h5c12.3 5.1 25.7 8 39.8 8s27.6-2.9 39.8-8h5c37.1 0 67.2 25.8 67.2 57.6v19.2z"></path></svg>';
$im->readImageBlob($svg);
$im->setImageFormat("png24");
header("Content-Type: image/png");
echo $im;
$im->writeImage('convert.png');
}
catch (ImagickException $e) {
echo $e;
}
$im->clear();
$im->destroy();
?>
Could anyone help me identify the error in this situation?