Edit pictures in PHP

Just curiosity…

How can i edit picture files in websites using php?

I once saw some websites where they asked you to write something and then the site would write that in the picture and save as the picture itself.

One example is this site: http://some_name.justgotowned.com/

but instead of a picture it uses flash animation.