function overlay($overlay, $position = 'center', $opacity = 1, $x_offset = 0, $y_offset = 0)
{
// Load overlay image
if (!$overlay instanceof SimpleImage) {
$overlay = new SimpleImage($overlay);
}
// Convert opacity
$opacity = $opacity * 100;
// Determine position
switch (strtolower($position)) {
case 'top left':
$x = 0 + $x_offset;
$y = 0 + $y_offset;
break;
case 'top right':
$x = $this->width - $overlay->width + $x_offset;
$y = 0 + $y_offset;
break;
case 'top':
$x = $this->width / 2 - $overlay->width / 2 + $x_offset;
$y = 0 + $y_offset;
break;
case 'bottom left':
$x = 0 + $x_offset;
$y = $this->height - $overlay->height + $y_offset;
break;
case 'bottom right':
$x = $this->width - $overlay->width + $x_offset;
$y = $this->height - $overlay->height + $y_offset;
break;
case 'bottom':
$x = $this->width / 2 - $overlay->width / 2 + $x_offset;
$y = $this->height - $overlay->height + $y_offset;
break;
case 'left':
$x = 0 + $x_offset;
$y = $this->height / 2 - $overlay->height / 2 + $y_offset;
break;
case 'right':
$x = $this->width - $overlay->width + $x_offset;
$y = $this->height / 2 - $overlay->height / 2 + $y_offset;
break;
case 'center':
default:
$x = $this->width / 2 - $overlay->width / 2 + $x_offset;
$y = $this->height / 2 - $overlay->height / 2 + $y_offset;
break;
}
// Perform the overlay
$this->imagecopymerge_alpha($this->image, $overlay->image, $x, $y, 0, 0, $overlay->width, $overlay->height, $opacity);
return $this;
}