(PECL imagick 2.0.0)
Imagick::resizeImage — 画像のサイズを変更する
$columns
, int $rows
, int $filter
, float $blur
[, bool $bestfit = false
] ) : bool指定した大きさと フィルタ で、画像のサイズを変更します。
注意: パラメータ
bestfitの挙動は Imagick 3.0.0 で変わりました。 これより前のバージョンでは、200x150 の画像に対して 400x400 を指定した場合は何もせずそのままになっていました。 Imagick 3.0.0 以降では、この画像は 400x300 に拡大されます。これが、 指定したサイズに対して「ベストフィット」する大きさだからです。bestfitを使う場合は、幅と高さの両方を指定しなければなりません。
columns画像の幅。
rows画像の高さ。
filterフィルタ定数 の一覧を参照ください。
blurblur 要素。> 1 はぼやけた状態、< 1 はシャープな状態を表します。
bestfitオプションの fit パラメータ。
成功した場合に TRUE を返します。
| バージョン | 説明 |
|---|---|
| 2.1.0 | オプションのパラメータ fit が追加され、 このメソッドは、比例形式の拡大・縮小をサポートするようになりました。 どちらかのパラメータにゼロを渡すと比例形式の拡大・縮小を行います。 |
例1 Imagick::resizeImage()
<?php
function resizeImage($imagePath, $width, $height, $filterType, $blur, $bestFit, $cropZoom) {
//The blur factor where > 1 is blurry, < 1 is sharp.
$imagick = new \Imagick(realpath($imagePath));
$imagick->resizeImage($width, $height, $filterType, $blur, $bestFit);
$cropWidth = $imagick->getImageWidth();
$cropHeight = $imagick->getImageHeight();
if ($cropZoom) {
$newWidth = $cropWidth / 2;
$newHeight = $cropHeight / 2;
$imagick->cropimage(
$newWidth,
$newHeight,
($cropWidth - $newWidth) / 2,
($cropHeight - $newHeight) / 2
);
$imagick->scaleimage(
$imagick->getImageWidth() * 4,
$imagick->getImageHeight() * 4
);
}
header("Content-Type: image/jpg");
echo $imagick->getImageBlob();
}
?>