public function drawRectangle($x, $y, $w, $h = null)
{
$x2 = $x + $w;
$y2 = $y + (null === $h ? $w : $h);
// Create an image resource.
$this->createResource();
// Set fill color and create rectangle.
if (null === $this->fillColor && null === $this->backgroundColor) {
$fill = $this->setColor(new Rgb(255, 255, 255));
} else {
if (null === $this->fillColor) {
$fill = $this->setColor($this->backgroundColor);
} else {
$fill = $this->setColor($this->fillColor);
}
}
imagefilledrectangle($this->resource, $x, $y, $x2, $y2, $fill);
// Create stroke, if applicable.
if (null !== $this->strokeColor) {
$stroke = $this->setColor($this->strokeColor);
if (null === $this->strokeWidth) {
$this->strokeWidth = 1;
}
imagesetthickness($this->resource, $this->strokeWidth);
imagerectangle($this->resource, $x, $y, $x2, $y2, $stroke);
}
$this->output = $this->resource;
return $this;
}