Yes it is possible.
Have a look at the gd library
Realize that one script can only output one type of product (e.g., a web-page, an image). In order to create an image, you need a script that outputs the image-information, and use it in your main document as a normal image:
<img src="MyImageScript.php?ImgId=3">
J.