Imagick::borderImage() method in PHP
The Imagick::borderImage() method is a PHP intrinsic function that draws a border around an image. This method adds a border around the image in the specified colour.
This function takes three parameters, which are listed above and described below:
$bordercolor: This argument is either an ImagickPixel object or a string that contains the border colour.
$width:The border width is controlled by the $width option.
$height: This argument is used to specify the height of the border.
The return type of the border Image function in PHP is of the Boolean type, which means the return type of this function will be either true or false depending upon the success or failure of the operation. The return type of the border Image function is true if the border is successfully created around the specified input image on the other hand if the border creation operation around the specified input image is failed then the return type of the border Image function is changed to false.
In this example, we have seen the use of the Border image function in PHP along with other major functions provided by PHP like set compress quality set image format set the fill colour and some others so in this example we have followed the sequence like that first of all we have created two image pixel objects one is of white and another is of black colour after the creation of these two image pixel objects we have used the draw image function to draw the basic image after the successful creation of the image that next function that we have used as a Border image function the border Image function is used to fill the border of the image with a particular colour specified by us after the successful filling of the border colour of that particular image the next step is to scale that image and save the result with the use of write Image function.
This is another example in which we have used the border Image function to distinguish between the different types of the extensions of our input image file. here in this example we have different cases depending upon the file extension of the input image file these cases are like assuming the input extension of the input image file is of gif format or PNG format or it is of JPG or JPEG format. depending upon the input Image extension we have defined the different set of instructions for each of these cases and for that we have used border-image function provided by PHP to change the border colour of the input image having different type of extension as specified in our above written example.
Thus, in this article, we have seen how we can use the border Image function in PHP to change the colour of the border of the input image we can change the border colour of the input image according to our need by specifying the particular colour as a parameter to our border Image function.