Make the code and test that it works, change extention to .jpg (if passing out jpg headers, gif for gif, png for png), and have the server parse those files for php
AddType application/x-httpd-php .jpg
You can put this in a .htaccess in that directory so all jpgs on server don't get parsed (some isps won't let you)
Alternatively, you could put it into the httpd.conf but this is not recommended plus you'd need access to the server.
Note: this will only work if you're hosting the image (you provide a link to the image in your sig/avatar)
This won't work if you're uploading the image.