PHP Conference Japan 2024

Imagick::borderImage

(PECL imagick 2, PECL imagick 3)

Imagick::borderImage在影像周圍加上邊框

描述

public Imagick::borderImage(mixed $bordercolor, int $width, int $height): bool

在影像周圍加上以 bordercolor ImagickPixel 物件定義的顏色的邊框。

參數

bordercolor

ImagickPixel 物件或包含邊框顏色的字串

width

邊框寬度

height

邊框高度

回傳值

成功時回傳 true

變更記錄

版本 描述
PECL imagick 2.1.0 現在允許使用代表顏色的字串作為第一個參數。之前的版本只允許使用 ImagickPixel 物件。

範例

範例 #1 Imagick::borderImage()

<?php
function borderImage($imagePath, $color, $width, $height) {
$imagick = new \Imagick(realpath($imagePath));
$imagick->borderImage($color, $width, $height);
header("Content-Type: image/jpg");
echo
$imagick->getImageBlob();
}

?>

新增筆記

使用者貢獻的筆記 1 筆筆記

-4
rosh3000 at gmail dot com
9 年前
若要取得具有確切尺寸的影像 (即新增空白),請使用 borderImage
$desired_width = 1000;
$desired_height = 1000;

$image->scaleImage($desired_width,$desired_height , true);
$image->borderImage('white', ($image->getImageWidth() - $desired_width) / 2,($image->getImageHeight() - $desired_height ) / 2);
To Top