PHP Conference Japan 2024

Imagick::resampleImage

(PECL imagick 2, PECL imagick 3)

Imagick::resampleImage將影像重新取樣至所需解析度

說明

public Imagick::resampleImage(
    float $x_resolution,
    float $y_resolution,
    int $filter,
    float $blur
): bool

將影像重新取樣至所需解析度。

參數

x_resolution

y_resolution

filter

blur

回傳值

成功時回傳 true

範例

範例 #1 Imagick::resampleImage()

<?php
function resampleImage($imagePath) {
$imagick = new \Imagick(realpath($imagePath));

$imagick->resampleImage(200, 200, \Imagick::FILTER_LANCZOS, 1);
header("Content-Type: image/jpg");
echo
$imagick->getImageBlob();
}

?>

新增筆記

使用者貢獻的筆記 3 則筆記

simon
9 年前
請注意,我在 Ubuntu Linux 15.10 上使用此函式時,CPU 使用率極高。改用 resizeImage 函式解決了此問題。
bleighty at dvidshub dot net
11 年前
請注意,如果我從此頁面正確理解,模糊值為 1 應該不會影響影像。
https://php.dev.org.tw/manual/en/imagick.resizeimage.php
anagai at yahoo dot com
13 年前
假設您想要降低上傳到網路的影像解析度。

以下程式碼會以任何解析度載入影像,並將其重新取樣至 72 dpi,然後另存為不同的檔案。

setImageResolution() 和 resampleImage() 的 dpi 應該與您重新取樣的 dpi 相同。

<?php
$image
= new Imagick();
$image->readImage('image.jpg');
$image->setImageResolution(72,72);
$image->resampleImage(72,72,imagick::FILTER_UNDEFINED,0);
$image->writeImage('image72.jpg');
?>
To Top