Сторона вашего вопроса на Python / CGI может быть такой простой, как эта, если вам просто нужно отправить существующее изображение:
import sys
# Send the Content-Type header to let the client know what you're sending
sys.stdout.write('Content-Type: image/png\r\n\r\n')
# Send the actual image data
with open('path/to/image.png', 'rb') as f:
sys.stdout.write(f.read())
Если, с другой стороны, вы динамически создаете изображения, например, с помощью PIL , вы можете сделать что-то вроде этого:
import sys
import Image, ImageDraw # or whatever
sys.stdout.write('Content-Type: image/png\r\n\r\n')
# Dynamically create an image
image = Image.new('RGB', (100, 100))
# ... etc ...
# Send the image to the client
image.save(sys.stdout, 'PNG')