代码最终看起来像这样:
function select($x, $y, $x2, $y2) {
if (! $this->selected) {
$this->copy = new MyImage($this->x, $this->y);
imagecopymerge($this->copy->img, $this->img, 0, 0, 0, 0, $this->x, $this->y, 100);
$this->copy->trans = imagecolorallocatealpha($this->copy->img, 0, 0, 0, 127);
imagealphablending($this->copy->img, false);
imagecolortransparent($this->copy->img, $this->copy->trans);
$this->selected = true;
}
$this->copy->rect($x, $y, $x2, $y2, $this->copy->trans, 1);
}
function deselect() {
if (! $this->selected) return false;
if (func_num_args() == 4) {
list($x, $y, $x2, $y2) = func_get_args();
imagecopymerge($this->copy->img, $this->img, $x, $y, $x, $y, $x2-$x, $y2-$y, 100);
}else{
imagealphablending($this->img, true);
imagecopymerge($this->img, $this->copy->img, 0, 0, 0, 0, $this->x, $this->y, 100);
$this->copy->__destruct();
$this->selected = false;
}
}
对于那些好奇的人,这里是两个类:
http://dev.expocom.nl/functions.php?id=104 (image.class.php)
http://dev.expocom.nl/functions.php?id=171 (MyImage.class.php extends image.class.php)