首页 > 编程开发 > PHP    日期:2021-11-15 / 来自互联网 / 浏览

php svg怎么转svg?

php imagick svg转成jpg

代码如下:

public function svgtojpg()
{
$image = '<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="400" height="300" viewBox="0,0,40,30" style="border:1px solid #cd0000;" version="1.1"
xmlns="http://www.w3.org/2000/svg">
<rect x="0" y="0" width="40" height="30" fill="#cd0000"/>
</svg>
';
$filename = 'ef.jpg';
/* $image = stripslashes($_POST['json']);
$filename = $_POST['filename'];*/
$unique = time();
$im = new \Imagick();
$im->readImageBlob($image);
$res = $im->getImageResolution();
$x_ratio = $res['x'] / $im->getImageWidth();
$y_ratio = $res['y'] / $im->getImageHeight();
$im->removeImage();
$im->setResolution($width_in_pixels * $x_ratio, $height_in_pixels * $y_ratio);
$im->readImageBlob($image);
$im->setImageFormat("jpeg");
$im->writeImage(__DIR__ . '/../../../Public/moban/images/1/humourised_'. $filename);
$im->clear();
$im->destroy();
}

觉得上面的内容有用吗?快来点个赞吧!

点赞() 我要打赏

温馨提示 : 本站内容来自会员投稿以及互联网,所有源码及教程均为作者总结编辑,请大家在使用过程中提前做好备份,以免发生无法预知的错误,源码类教程请勿直接用于生产环境!

 可能感兴趣的文章