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 — 画像の解像度を設定する
説明
bool Imagick::setResolution
( float $x_resolution
, float $y_resolution
)
警告
この関数は、 現在のところ詳細な情報はありません。引数のリストのみが 記述されています。
画像の解像度を設定します。
パラメータ
- x_resolution
-
- y_resolution
-
返り値
成功した場合に TRUE を返します。
Imagick::setResolution
znupi69 com
23-Aug-2008 06:55
23-Aug-2008 06:55
