PHPTS:一键免费搭建 Nginx + PHP + MySQL 运行环境

Imagick::scaleImage

(PECL imagick 2.0.0)

Imagick::scaleImageScales the size of an image

说明

Imagick::scaleImage ( int $cols , int $rows [, bool $bestfit = FALSE [, bool $legacy = FALSE ]] ) : bool

Scales the size of an image to the given dimensions. The other parameter will be calculated if 0 is passed as either param.

Note: 参数 bestfit 的特性在 Imagick 3.0.0 中已改变。在此版本以前,当目标尺寸设为 400x400 时,原尺寸为 200x150 的图像将不会被改变。自 Imagick 3.0.0 起,源图像将会被放大到 400x300 因为这将更好的适合目标尺寸。当使用参数 bestfit 时,必须同时给出宽度和高度。

参数

cols

rows

bestfit

返回值

成功时返回 TRUE

错误/异常

错误时抛出 ImagickException。

更新日志

版本 说明
2.1.0 Added optional fit parameter. This method now supports proportional scaling. Pass zero as either parameter for proportional scaling.

范例

Example #1 Imagick::scaleImage()

<?php
function scaleImage($imagePath) {
    
$imagick = new \Imagick(realpath($imagePath));
    
$imagick->scaleImage(150150true);
    
header("Content-Type: image/jpg");
    echo 
$imagick->getImageBlob();
}

?>