$width
$width : integer
Image width in pixels
Class Rectangle
$fillColor : \Grafika\Color
$borderColor : \Grafika\Color
__construct(integer $width, integer $height, array $pos = array(0, 0), integer $borderSize = 1, \Grafika\Color|string|null $borderColor = '#000000', \Grafika\Color|string|null $fillColor = '#FFFFFF')
Creates a rectangle.
integer | $width | Width of rectangle in pixels. |
integer | $height | Height in pixels. |
array | $pos | Array of X and Y position. X is the distance in pixels from the left of the canvass to the left of the rectangle. Y is the distance from the top of the canvass to the top of the rectangle. Defaults to array(0,0). |
integer | $borderSize | Size of the border in pixels. Defaults to 1 pixel. Set to 0 for no border. |
\Grafika\Color|string|null | $borderColor | Border color. Defaults to black. Set to null for no color. |
\Grafika\Color|string|null | $fillColor | Fill color. Defaults to white. Set to null for no color. |
getFillColor() : \Grafika\Color
getBorderColor() : \Grafika\Color
draw(\Grafika\ImageInterface $image) : \Grafika\ImageInterface
\Grafika\ImageInterface | $image |
<?php
namespace Grafika\Gd\DrawingObject;
use Grafika\DrawingObject\Rectangle as Base;
use Grafika\DrawingObjectInterface;
use Grafika\Gd\Editor;
/**
* Class Rectangle
* @package Grafika
*/
class Rectangle extends Base implements DrawingObjectInterface
{
public function draw($image)
{
$x1 = $this->pos[0];
$x2 = $x1 + $this->getWidth();
$y1 = $this->pos[1];
$y2 = $y1 + $this->getHeight();
if( null !== $this->fillColor ){
list($r, $g, $b, $alpha) = $this->fillColor->getRgba();
$fillColorResource = imagecolorallocatealpha($image->getCore(), $r, $g, $b, Editor::gdAlpha($alpha));
imagefilledrectangle($image->getCore(), $x1, $y1, $x2, $y2, $fillColorResource);
}
// Create borders. It will be placed on top of the filled rectangle (if present)
if ( 0 < $this->getBorderSize() and null !== $this->borderColor) { // With border > 0 AND borderColor !== null
list($r, $g, $b, $alpha) = $this->borderColor->getRgba();
$borderColorResource = imagecolorallocatealpha($image->getCore(), $r, $g, $b, Editor::gdAlpha($alpha));
imagerectangle($image->getCore(), $x1, $y1, $x2, $y2, $borderColorResource);
}
return $image;
}
}