function flip($direction)
{
$new = imagecreatetruecolor($this->width, $this->height);
imagealphablending($new, false);
imagesavealpha($new, true);
switch (strtolower($direction)) {
case 'y':
for ($y = 0; $y < $this->height; $y++) {
imagecopy($new, $this->image, 0, $y, 0, $this->height - $y - 1, $this->width, 1);
}
break;
default:
for ($x = 0; $x < $this->width; $x++) {
imagecopy($new, $this->image, $x, 0, $this->width - $x - 1, 0, 1, $this->height);
}
break;
}
$this->image = $new;
return $this;
}