Cover Image for Imagick::borderImage() method in PHP
219 views

Imagick::borderImage() method in PHP

In PHP, Imagick::borderImage() is a method of the Imagick class, which is part of the Imagick extension. The Imagick extension is a powerful PHP library that allows you to manipulate images using the ImageMagick software.

The borderImage() method is used to add a border around an image. It allows you to specify the border’s width, height, border color, and the border’s surrounding width (the space between the image and the border).

Here’s the syntax of the borderImage() method:

public Imagick::borderImage($borderColor, $width, $height)

Parameters:

  • $borderColor: The color of the border. It can be a string representing a color name (e.g., “red”, “blue”) or an ImagickPixel object representing a specific color.
  • $width: The width of the border.
  • $height: The height of the border.

Return value:

  • The method returns true on success.

Example:

// Create a new Imagick object and read an image file
$imagick = new Imagick('input.jpg');

// Define the border color as black
$borderColor = 'black';

// Add a border of 10 pixels in width and height
$borderWidth = 10;
$borderHeight = 10;

// Add the border to the image
$imagick->borderImage($borderColor, $borderWidth, $borderHeight);

// Set the output image format to JPEG
$imagick->setImageFormat('jpeg');

// Output the modified image to the browser
header('Content-Type: image/jpeg');
echo $imagick;

In this example, we create an Imagick object and load an image file named input.jpg. We then specify the border color as black and set the border width and height to 10 pixels. The borderImage() method is used to add the specified border to the image, and then the modified image is output to the browser.

Please note that to use the Imagick class and its methods, you need to have the Imagick extension installed and enabled on your PHP server. Additionally, you should have the ImageMagick software installed on the server for the Imagick extension to work properly.

YOU MAY ALSO LIKE...

The Tech Thunder

The Tech Thunder

The Tech Thunder


COMMENTS