Home > Article > Backend Development > How to convert php svg to jpg
php svg to jpg method: 1. Create a PHP sample file; 2. Use the "public function svgtojpg(){$image =...}" method to achieve conversion.
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 = '<?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(); }
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!