note 85284 added to function.imagick-setresolution
| From: | znupi69com at osu1 dot php dot net | Date: | Sat, 23 Aug 2008 18:55:36 +0000 |
| Subject: | note 85284 added to function.imagick-setresolution | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-143772@lists.php.net to get a copy of this message | ||
If you want to resize a vector-graphics image (such as SVG) to a certain dimension in pixels,
without losing quality, you have to do this:
<?php
$im = new Imagick();
$im->readImage("/path/to/image.svg");
$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->readImage("/path/to/image.svg");
// Now you can do anything with the image, such as convert to a raster image and output it to the
browser:
$im->setImageFormat("png");
header("Content-Type: image/png");
echo $im;
?>
It took me a couple or so days to figure this out, I hope this saves someone else's time! Have
fun! :-)
----
Server IP: 69.147.83.197
Probable Submitter: 77.81.204.37
----
Manual Page -- http://www.php.net/manual/en/function.imagick-setresolution.php
Edit -- https://master.php.net/note/edit/85284
Del: integrated -- https://master.php.net/note/delete/85284/integrated
Del: useless -- https://master.php.net/note/delete/85284/useless
Del: bad code -- https://master.php.net/note/delete/85284/bad+code
Del: spam -- https://master.php.net/note/delete/85284/spam
Del: non-english -- https://master.php.net/note/delete/85284/non-english
Del: in docs -- https://master.php.net/note/delete/85284/in+docs
Del: other reasons-- https://master.php.net/note/delete/85284
Reject -- https://master.php.net/note/reject/85284
Search -- https://master.php.net/manage/user-notes.php