I write a code that converts SVG script to PNG image. I met with two problems:
All the images nodes in the SVG script - their width is stretch. I want to define only the height, and the width leave to auto. In the SVG itself it seem good.
I tried to embed curved text - but in the PNG output I didn't see it.
This is my SVG script:
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="350px" height="100px" viewBox="0 0 350 100">
<defs>
<path d="M 0,0 a 142.5,142.5 0 1,1 285,0 a 142.5,142.5 0 1,1 -285,0" id="curvedTextPath0" transform="translate(30,162)"></path>
</defs>
<image height="100px" width="350px" xlink:href="https://concepta.co.il/wp-content/uploads/2020/02/7-300x208.jpg" x="0px" y="0px" visibility="visible" preserveAspectRatio="xMidYMid meet"></image>
<text fill="#2f299a" text-anchor="middle" font-size="25px" x="30" y="20" visibility="visible" font-family="M PLUS Rounded 1c">
<textPath startOffset="22%" xlink:href="#curvedTextPath0">lehcar</textPath>
</text>
</svg>
This is my PHP code:
$im = new Imagick();
$im->setBackgroundColor(new ImagickPixel('transparent'));
$im->readImageBlob($svg);
$im->setImageFormat("png32");
$folder_path = WP_CONTENT_DIR. 'uploads/concepta_orders_files';
if (!file_exists($folder_path)) {
mkdir($folder_path, 0777, true);
}
$img_path = $folder_path . '/' . $fileName;
$im->writeImage($img_path);
$im->clear();
$im->destroy();
Thanks for advance!
What I have tried:
I tried to validate the svg code - is valid.
I tried to set the property
preserveAspectRatio="xMidYMid meet"
to the images - id didn't help.
I also changed the image format.