Home >Backend Development >PHP Problem >How to convert php svg to jpg

How to convert php svg to jpg

藏色散人
藏色散人Original
2021-11-15 09:58:462496browse

php svg to jpg method: 1. Create a PHP sample file; 2. Use the "public function svgtojpg(){$image =...}" method to achieve conversion.

How to convert php svg to jpg

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

How to convert php svg to svg?

php imagick svg to jpg

The code is as follows:

public function svgtojpg()
{
$image = &#39;<?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>
&#39;;
$filename = &#39;ef.jpg&#39;;
/* $image = stripslashes($_POST[&#39;json&#39;]);
$filename = $_POST[&#39;filename&#39;];*/
$unique = time();
$im = new \Imagick();
$im->readImageBlob($image);
$res = $im->getImageResolution();
$x_ratio = $res[&#39;x&#39;] / $im->getImageWidth();
$y_ratio = $res[&#39;y&#39;] / $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__ . &#39;/../../../Public/moban/images/1/humourised_&#39;. $filename);
$im->clear();
$im->destroy();
}

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to convert php svg to jpg. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn