PHP 8.3.4 Released!

Imagick::borderImage

(PECL imagick 2, PECL imagick 3)

Imagick::borderImage画像の周りを枠線で囲む

説明

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

画像の周りを枠線で囲みます。枠線の色は 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();
}

?>

add a note

User Contributed Notes 1 note

up
-4
rosh3000 at gmail dot com
8 years ago
To get an image with exact dimensions (i.e. add whitespace) use with 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