User:Stonestone/pythonnotes

From XPUB & Lens-Based wiki
< User:Stonestone
Revision as of 11:50, 25 November 2015 by Stonestone (talk | contribs) (Created page with "===大明白区=== <pre>目前,懒得弄 </pre> ===等回复区=== <pre> from PIL import Image, ImageDraw , ImageFont from cStringIO import StringIO #其实不太懂StringIO...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

大明白区

目前,懒得弄

等回复区

from PIL import Image, ImageDraw , ImageFont
from cStringIO import StringIO #其实不太懂StringIO这个模块。
import random

f = ImageFont.truetype("/Users/Stone/Desktop/Ptah-Regular.otf", size=300)

of = open("frames.mjpeg", "wb") #不太懂

for i in range(100):
    p = i/99.0 #不明白为什么要除以99为什么不是除以100,老师说了一嘴我没听明白。。
    l = p*(1920-50)
    print p , l
    r = random.randint(1,225)
    g = random.randint(220,255)
    b = random.randint(111,225)
    im = Image.new("RGB", (1920,1080) , color=(r,g,b)) #("mode",(size),(color)) 
    draw = ImageDraw.Draw(im)
    sc=p*255
    tp = 80+(p*1870)
    draw.text((tp,680), str(i), fill=(255,0,0),font=f)
    draw.text((tp-2,680-2), str(i), fill=(0,0,0),font=f)
    draw.text((tp+2,680+2), str(i), fill=(0,0,0),font=f)
    buf = StringIO() #不太懂buf指的是什么。。
    im.save(buf, format="jpeg")
    of.write(buf.getvalue()) #of = bucket
    
    print i
print "done"