Pages

Tuesday, 27 October 2020

Pure CGI: Generating Image on the fly

 1. BASH

#!/usr/bin/bash
echo -ne 'Content-Type: image/gif\r\n\r\n'

cat openbsd.gif

2. Python

#!/usr/bin/env python3
# HTTP header
import sys, os
print('Content-Type: image/gif\r\n\r\n', end='')
sys.stdout.flush()

img = open(r'openbsd.gif','rb')
data = img.read()
img.close()

out = os.fdopen(sys.stdout.fileno(), 'wb')
out.write(data)


No comments:

Post a Comment