So I'm making an image with black background. My quest is to add white border around the image inside with 2px padding between border and the image.
- Uploading image
- Then I'm creating white border around it.
- Then I'm creating black background (image) with bigger width and height of the uploaded image.
- At the end I add the original image with border to the center of created black image.
So I'm stucked at the second point, where the white border is being created. My all code looks like this:
public function output()
{
$this->__set_image_size();
# setting temp image location
$this->settings['__temp_image'] = $this->settings['__upload_dir']['temp'] . $this->temp_image_name . '.jpg';
# generating image
$this->__generate_background();
$this->__load_image();
$this->__draw_white_border();
$this->__insert_image_to_wrapper();
# destroy temp image data
//imagedestroy($this->settings['__temp_image']);
return $this->settings;
}
and the function __draw_white_border
:
private function __draw_white_border()
{
# draw white border
$color_white = ImageColorAllocate($this->image_inside, 255, 255, 255);
$this->__draw_border($this->image_inside, $color_white, 4);
}
private function __draw_border(&$img, &$color, $thickness)
{
$x = ImageSX($img);
$y = ImageSY($img);
for ( $i = 0; $i < $thickness; $i ++ )
ImageRectangle($img, $i, $i, $x --, $y --, $color);
}
the main question is: how to add padding between border and the image at the second point of the list or how to make gradiant border with 2px black color and 4px white color?