This is the svg:
Code: Select all
<svg version="1.1" width="340" height="470">
<clipPath id="imgMask" clipPathUnits="userSpaceOnUse"><path d="m276.5,1.5l-138,0c-14.35899,0 -27,16.64101 -27,31l0,336c0,13.39001 12.73,24.40997 26.091,25.83899c0.259,-1.08002 1.25,-1.83899 5.039,-1.83899l129.73999,0c3.80099,0 4.785,0.76398 5.04001,1.84998c13.11398,-1.323 24.09,-11.46997 24.09,-24.84998l0,-337c0,-14.35899 -10.64099,-31 -25,-31zm-106,50l-29,0c-11.59801,0 -21,-9.40199 -21,-21s9.40199,-21 21,-21l29,0c11.59799,0 21,9.40199 21,21s-9.40201,21 -21,21z" fill="red" stroke="#34ACE4" stroke-width="2" id="outline"></path></clipPath>
<g id="canvasPreview" clip-path="url(#imgMask)" fill-rule="evenodd">
<image x="28.5" y="-26.5" width="343" height="441" id="userImagePrev" center="true" transform="matrix(1 0 0 1 0 0)" xlink:href="doina.jpg"></image>
</g>
<defs><filter id="blackWhitePicture"><feComposite result="litPaint" operator="arithmetic" in="SourceGraphic" in2="SourceGraphic" k1="0" k2="1" k3="0" k4="0"></feComposite><feColorMatrix result="grayscale" type="saturate" values="0"></feColorMatrix></filter></defs>
</svg>
Code: Select all
$im = new Imagick();
//$im->setBackgroundColor(new ImagickPixel('transparent'));
$im->readImageBlob($svg);
$im->clipPathImage("#1", true);
$im->setImageFormat("png32");
header('Content-type: image/png');
echo $im;
Code: Select all
( ! ) Fatal error: Uncaught exception 'ImagickException' with message 'no clip path defined `/tmp/magick-XXyrLIE6': /tmp/magick-XXyrLIE6.cache @ error/image.c/ClipImagePath/739' in /var/www/casewebsite/catalog/controller/product/custom.php on line 240
( ! ) ImagickException: no clip path defined `/tmp/magick-XXyrLIE6': /tmp/magick-XXyrLIE6.cache @ error/image.c/ClipImagePath/739 in /var/www/casewebsite/catalog/controller/product/custom.php on line 240
Code: Select all
convert test.svg +clip -alpha transparent result.png
Thank you!