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
Descrição
bool Imagick::setResolution
( float $x_resolution
, float $y_resolution
)
Aviso
Esta função não está documentada; somente a lista de argumentos está disponível.
Sets the image resolution.
Parâmetros
- x_resolution
-
- y_resolution
-
Valor Retornado
Retorna TRUE em sucesso.
Imagick::setResolution
znupi69 com
23-Aug-2008 06:55
23-Aug-2008 06:55
