array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'imagick.scaleimage.php', 1 => 'Imagick::scaleImage', 2 => 'Scales the size of an image', ), 'up' => array ( 0 => 'class.imagick.php', 1 => 'Imagick', ), 'prev' => array ( 0 => 'imagick.sampleimage.php', 1 => 'Imagick::sampleImage', ), 'next' => array ( 0 => 'imagick.segmentimage.php', 1 => 'Imagick::segmentImage', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/imagick/imagick/scaleimage.xml', ), 'history' => array ( ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); contributors($setup); ?>
(PECL imagick 2, PECL imagick 3)
Imagick::scaleImage — Scales the size of an image
$columns,$rows,$bestfit = false,$legacy = falseScales the size of an image to the given dimensions. The other parameter will be calculated if 0 is passed as either param.
注意: 参数
bestfit的特性在 Imagick 3.0.0 中已改变。在此版本以前,当目标尺寸设为 400x400 时,原尺寸为 200x150 的图像将不会被改变。自 Imagick 3.0.0 起,源图像将会被放大到 400x300 因为这将更好的适合目标尺寸。当使用参数bestfit时,必须同时给出宽度和高度。
columns
rows
bestfit
成功时返回 true。
错误时抛出 ImagickException。
| 版本 | 说明 |
|---|---|
| PECL imagick 2.1.0 | Added optional fit parameter. This method now supports proportional scaling. Pass zero as either parameter for proportional scaling. |
示例 #1 Imagick::scaleImage()
<?php
function scaleImage($imagePath) {
$imagick = new \Imagick(realpath($imagePath));
$imagick->scaleImage(150, 150, true);
header("Content-Type: image/jpg");
echo $imagick->getImageBlob();
}
?>