You can read all about
image functions at the
PHP manual.
There are many tutorials out there that explain how to do this. A simple search for
php "dynamic images" tutorial got me a lot of good articles.
However, I'd suggest you learn the language first. Going for a script like this without knowing the basic language structure is like trying to write a book in Chinese without having studied it.