Well, you can certainly do it with PHP, but you should be able to do it via GScript with
TDrawingPanel.
Jer made an example of what you can do with
TDrawingPanel here. See also the wiki page
here. Sounds like
drawImageRectangle is what you're looking for.