php svg怎么转jpg

来自:互联网
时间: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();
}
返回顶部
顶部