php svg to jpg method: 1, create a PHP sample file; 2, by "public function svgtojpg(){$image =...}" method to achieve the conversion.
How to convert svg to svg in php?
codes:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
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();
}
|
Related articles
The two basic output methods of php are "echo" and "print". echo is used to output one or more strings, which can take multiple arguments and have no return value, with the syntax "echo($ str)"; and print is used to output a string that can only take one
php image display a mess of solutions: 1, open the corresponding PHP code file; 2, in the page header plus "header ("Content-Type: image/jpg");" code to declare the image type can be.
php can not load js css solution: 1, check the correct path to load; 2, prohibit the use of absolute path; 3, use relative path to load the file can be.
php query user ip method: 1, get user ip by "$_SERVER["REMOTE_ADDR"]" way; 2, get user ip by "($user_IP) ? $user_IP : $_SERVER["REMOTE_ADDR"];" to get the user ip and so on.
Inversion methods: 1. use "explode(' ',$str)" statement to convert string to array; 2. use "array_reverse($arr)" statement to invert the array and return the array in the reverse order of elements; 3. use "implode(' ',$arr)" statement to convert the inver
In php, you can use the max() function to get the maximum value among several numbers. The function works by calculating and returning the maximum value among several specified values, with the syntax "max(value1,value2,...) ;".
php image to base64 method: 1, get an image address; 2, through the "chunk_split(base64_encode($gambar));" method to convert the image to base64 string format can be.
How to merge arrays in PHP? To do this we need to use the array_merge function and the array_merge_recursive function. Here we will introduce these two functions separately.
php array only take the first two elements of the method: 1, use the array_splice () function, syntax "array_splice($arr,0,2)"; 2, use the array_slice () function, syntax "array_slice($arr,0,2)".
String is an important data type in PHP, which how to compare strings is also very common in our development work, there are many kinds of comparison methods to compare strings, here we will introduce the more commonly used several comparison methods.