script type text javascript var height innerHeight var width innerWidt

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<script type="text/javascript">
var height = innerHeight;
var width = innerWidth;
document.body.background = "http://localhost:8000/utils/genback/?width="+width+"&height="+height;
document.body.style.backgroundAttachment = 'fixed';
document.body.style.backgroundPosition = 'right center';
</script>
/utils/genback/
#-*-coding:utf8-*-
from PIL import Image, ImageDraw
from django.http import HttpResponse
def generation_background(request):
if request.method == 'GET':
screen_width = int(request.GET['width'])
screen_height = int(request.GET['height'])
else:
screen_width = 1024
screen_height = 768
COLOR = (240, 239, 239, 128)
image = Image.new("RGBA", (screen_width, screen_height), (0,0,0,0))
draw = ImageDraw.Draw(image)
draw.ellipse((100, -10, 100+screen_width, -30+screen_width), fill=COLOR, outline=COLOR)
del draw
response = HttpResponse(mimetype="image/png")
image.save(response, 'PNG')
return response