Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Give border to image created in PHP

Tags:

php

gd

How do I give a border to an image created using PHP?

like image 595
DEVOPS Avatar asked Jun 09 '10 13:06

DEVOPS


People also ask

How do you change the border color of an image in HTML?

Add a border using HTMLWithin the img tag, add the border: #000000 6px outset; to the style attribute. Where you can enter your own color code, border width, and border style in the code.

How do you put a background image as a border in CSS?

The border-image property allows you to specify an image to be used as the border around an element. The border-image property is a shorthand property for: border-image-source. border-image-slice.


1 Answers

function drawBorder(&$img, &$color, $thickness = 1) 
{
    $x1 = 0; 
    $y1 = 0; 
    $x2 = ImageSX($img) - 1; 
    $y2 = ImageSY($img) - 1; 

    for($i = 0; $i < $thickness; $i++) 
    { 
        ImageRectangle($img, $x1++, $y1++, $x2--, $y2--, $color); 
    } 
}

Then the usage would just to do.

$color = imagecolorallocate($img, 255, 0, 0);
drawBorder($img,$color, 255);
like image 183
RobertPitt Avatar answered Oct 27 '22 11:10

RobertPitt