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! :-)
Imagick::setResolution
(PECL imagick 2.0.0)
Imagick::setResolution — Sets the image resolution
Beschreibung
bool Imagick::setResolution
( float $x_resolution
, float $y_resolution
)
Warnung
Diese Funktion ist bis jetzt nicht dokumentiert. Es steht nur die Liste der Argumente zur Verfügung.
Sets the image resolution.
Parameter-Liste
- x_resolution
-
- y_resolution
-
Rückgabewerte
Liefert TRUE bei Erfolg.
Imagick::setResolution
znupi69 com
23-Aug-2008 06:55
23-Aug-2008 06:55
