PHP 8.3.4 Released!

Imagick::borderImage

(PECL imagick 2, PECL imagick 3)

Imagick::borderImageRodea la imagen con un borde

Descripción

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

Rodea la imagen con un borde del color definido por el objeto ImagickPixel de color de borde.

Parámetros

bordercolor

Objeto ImagickPixel o una cadena que contiene el color del borde

width

Ancho del borde

height

Alto del borde

Valores devueltos

Devuelve true en caso de éxito.

Historial de cambios

Versión Descripción
PECL imagick 2.1.0 Ahora se permite que una cadena represente el color como el primer parámetro. Versiones anteriores sólo permitían un objeto ImagickPixel.

Ejemplos

Ejemplo #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