Regarding the image_flip function discussed in the notes here, don't forget to support transparency.
AFTER:
$imgdest = imagecreatetruecolor($width, $height);
ADD:
imagealphablending($imgdest, false);
imagesavealpha($imgdest, true);
In another post here it mentioned you didn't have to use the imagesavealpha function, but I found without it the background transparency can turn the background canvas black.