def render(self, text, font): # calculate the buffer size for the ticker text image = Image.new('1', (0, 0)) W, _ = Draw(image).textsize(text=text, font=font) H = self.H # render the ticker image = Image.new('1', (W, H), color=0) Draw(image).text((0, 0), text=text, font=font, fill=0xff) #image.show(command='display') return image
def apply_filter(self, image, _config): highgui.cvQueryFrame(self.camera) im = highgui.cvQueryFrame(self.camera) pilwebcam_image = opencv.adaptors.Ipl2PIL(im) pilwebcam_image.thumbnail( (int((pilwebcam_image.size[0] / 100.0) * _config['width']), int((pilwebcam_image.size[1] / 100.0) * _config['height']))) ## Border from ImageDraw import Draw drawing = Draw(pilwebcam_image) # top line drawing.line(((0, 0), (pilwebcam_image.size[0], 0)), fill=_config['border_colour']) # left line drawing.line(((0, 0), (0, pilwebcam_image.size[1])), fill=_config['border_colour']) # right line drawing.line(((pilwebcam_image.size[0] - 1, 0), (pilwebcam_image.size[0] - 1, pilwebcam_image.size[1])), fill=_config['border_colour']) # bottow line drawing.line(((0, pilwebcam_image.size[1] - 1), (pilwebcam_image.size[0], pilwebcam_image.size[1] - 1)), fill=_config['border_colour']) image.paste(pilwebcam_image, (10, 10)) return image
def showHost(): (W, H) = (display.W, display.H) image = Image.new('1', (W, H)) draw = Draw(image) top = random.randint(1, 170) tuxicon.Y = top tuxicon.refresh(draw) hostname = platform.node() ipaddr = getIpAddr() text = '%s %s' % (hostname, ipaddr) (w, h) = draw.textsize(text, font16) draw.text((80, top + 0), text=text, font=font16, fill=111) text = '%s %s' % (platform.system(), platform.release()) (w, h) = draw.textsize(text, font16) draw.text((80, top + 20), text, font=font16, fill=111) (days, hours, minutes) = getUptime() text = 'uptime %dd %dh %dm' % (days, hours, minutes) (w, h) = draw.textsize(text, font16) draw.text((80, top + 40), text, font=font16, fill=111) display.bitmap((0, 0), image) time.sleep(INTERVAL)
def gen_one(text, size): i = Image.new("RGB", size, (255, 255, 255)) d = Draw(i) y = 0 for line in text.splitlines(): d.text((LMARGIN, y), line, font=FONT, fill='black') y += DELTA_Y i.show()
def __init__(self, scheduler, rect): Widget.__init__(self, scheduler, rect) draw = Draw(Image.new('1', (0,0))) for size in xrange(100): self.font = ImageFont.truetype('trebuc.ttf', 100-size) (w,h) = draw.textsize('Wednesday', self.font) if w < self.W: break
def refresh(self, display): (W, H) = (self.W, self.H) image = Image.new('1', (W, H)) draw = Draw(image) self.render(draw) display.bitmap((self.X, self.Y), image, fill='#fff')
def gen_diff(r1, r2, diff, size): i = Image.new("RGB", size, (255, 255, 255)) d = Draw(i) font = ImageFont.truetype('ProFontWindows.ttf', 12) y = 0 print diff raw_input("is that what you wanted?") for g in groupdiffs(diff): print g raw_input("is that what you wanted?")
def alert(self, interval=10): (W, H) = (self.display.W, self.display.H) image = Image.new('1', (W, H)) draw = Draw(image) self.render(draw) self.display.bitmap((0, 0), image, fill=1) time.sleep(interval) self.display.clear()
def render(self): (W,H) = (self.W, self.H) image = Image.new('1', (W,H), color=0) draw = Draw(image) draw.text((0,1), time.strftime('%A'), font=self.font, fill=1) draw.text((0,H*5/11), time.strftime('%d %b %Y'), font=self.font, fill=1) L = W - 93 return image
def showProc(): # # reduce screen burn in by using some of the real estate to move # the image around # top = random.randint(1, 100) cputype.Y = top top += 40 loadavg.Y = top cpubusy.Y = top cputemp.Y = top top += 40 memfree.Y = top + 0 swapfree.Y = top + 32 diskfree.Y = top diskfree.update() # # for each sample in the interval # for moment in xrange(INTERVAL): # # refresh the indicators # (W, H) = (display.W, display.H) image = Image.new('1', (W, H)) draw = Draw(image) cputype.refresh(draw) loadavg.refresh(draw) cpubusy.refresh(draw) cputemp.refresh(draw) memfree.refresh(draw) swapfree.refresh(draw) diskfree.refresh(draw) display.bitmap((0, 0), image, fill='#fff') #image.save('proc.png') time.sleep(1)
def showMail(): if mail.mail.messages > 0: (W, H) = (display.W, display.H) image = Image.new('1', (W, H)) draw = Draw(image) top = random.randint(1, 200) mail.Y = top mail.refresh(draw) display.bitmap((0, 0), image) time.sleep(INTERVAL)
def render(self): (W,H) = (self.W, self.H) image = Image.new('1', (W,H), color=0) draw = Draw(image) t = time.localtime() hour = t.tm_hour%12 if hour == 0: hour = 12 text = '%d:%02d' % (hour, t.tm_min) (w,h) = draw.textsize(text, self.font) draw.text((-3,-h/6), text=text, font=self.font, fill=1) return image
def __init__(self, scheduler, rect): Widget.__init__(self, scheduler, rect) draw = Draw(Image.new('1', (0,0))) for size in xrange(100): self.font = ImageFont.truetype('trebuc.ttf', 100-size) (w,h) = draw.textsize('77', self.font) if w < self.W-36: break # regexes for parsing weather reports self.icontag = re.compile('<icon_url_name>(.+).jpg</icon_url_name>') self.tempftag = re.compile('<temp_f>(\d+)</temp_f>') self.update()
def __init__(self, scheduler, rect, mail=None): Widget.__init__(self, scheduler, rect) draw = Draw(Image.new('1', (0,0))) for size in xrange(100): self.font = ImageFont.truetype('trebuc.ttf', 100-size) (w,h) = draw.textsize('7', self.font) if w < self.W-32: break if mail == None: mail = gmail.GmailStatus() self.mail = mail self.mailicon = Image.open('mail.gif').convert('L').point(lambda x: 255-x, mode='1') self.update()
def apply_filter(self, image, _config): # OpenCV sucks, it keeps all frames cached so when I query them # they are old frames. I delete the camera object and get a new one # so i can query the current frame only. # this is the only solution i could work out to this problem. del self.camera self.camera = cv.CaptureFromCAM(-1) im = cv.QueryFrame(self.camera) # HEY HERE IS SOMETHING REALLY FUNNY # OPENCV USES BGR FOR IT'S INTERNAL IMAGE FORMAT # WOW # SO STANDARD GUYS # FAN-F*****G-TASTIC # I DIDN'T TOTALLY JUST SPEND THREE HOURS WORKING THAT OUT # GREAT STUFF # YOUR OWN EXAMPLE CODE FOR CONVERTING TO A PIL IMAGE DOESN'T TAKE THIS INTO ACCOUNT AT ALL # WTFFFFFFFFFFF pilwebcam_image = Image.fromstring("RGB", cv.GetSize(im), im.tostring()[::-1]).rotate(180) pilwebcam_image = pilwebcam_image.resize( (int((pilwebcam_image.size[0] / 100.0) * _config['width']), int((pilwebcam_image.size[1] / 100.0) * _config['height'])), Image.ANTIALIAS) ## Border drawing = Draw(pilwebcam_image) # top line drawing.line(((0, 0), (pilwebcam_image.size[0], 0)), fill=_config['border_colour']) # left line drawing.line(((0, 0), (0, pilwebcam_image.size[1])), fill=_config['border_colour']) # right line drawing.line(((pilwebcam_image.size[0] - 1, 0), (pilwebcam_image.size[0] - 1, pilwebcam_image.size[1])), fill=_config['border_colour']) # bottow line drawing.line(((0, pilwebcam_image.size[1] - 1), (pilwebcam_image.size[0], pilwebcam_image.size[1] - 1)), fill=_config['border_colour']) image.paste(pilwebcam_image, (10, 10)) return image
def render(self): (W,H) = (self.W, self.H) image = Image.new('1', (W,H), color=0) draw = Draw(image) newmail = self.mail.messages if newmail > 0: draw.bitmap((0,2), self.mailicon, fill=1) text = '%d' % newmail (w,h) = draw.textsize(text, self.font) draw.text((30,(32-h)/2), text=text, font=self.font, fill=1) return image
def randomPenguin(interval=0): global Px, Py penguin = Image.open('tux.jpg') _, _, w, h = penguin.getbbox() for i in xrange(interval * 2): (W, H) = (display.W, display.H) image = Image.new('1', (W, H)) draw = Draw(image) Px += random.randint(-2, 2) Px = max(Px, 0) Px = min(Px, W - w) Py += random.randint(-2, 2) Py = max(Py, 0) Py = min(Py, H - h) draw.bitmap((Px, Py), penguin, fill=1) display.bitmap((0, 0), image) time.sleep(0.5)
def render(self): (W,H) = (self.W, self.H) image = Image.new('1', (W,H), color=0) draw = Draw(image) try: text = self.tempf (w,h) = draw.textsize(text, self.font) Y = (32-h)/2 draw.text((30,Y), text, font=self.font, fill=1) X = 30 + w draw.ellipse((X-2,2,X+2,6), outline=1, fill=0) icon = Image.open(self.icon+'.gif').convert('L').point(lambda x: 255-x, mode='1') draw.bitmap((0,2), icon, fill=1) except: pass return image
def text(self, xy, text, fill=None, font=None, anchor=None): #text = text.replace(' ','_') # nasty workaround for PIL bug on amd64 image = self.image.copy() Draw(image).text(xy, text, fill, font, anchor) self.refresh(image)
print "!! Scale must be a positive number !!" sys.exit(1) padding = options.padding + outline size = (scale * len(logo)) + (2 * padding) if invert: background, color = color, background logo = [[not i for i in row] for row in logo] # ------------------------------------------------------------------------------ # Render # ------------------------------------------------------------------------------ im = new('RGB', (size, size), background) draw = Draw(im) if invert: pass if border: start = padding - 1 end = size - padding draw.rectangle([(start, start), (end, end)], outline=border) for y, row in enumerate(logo): for x, pixel in enumerate(row): if pixel: xfactor = (x * scale) + padding yfactor = (y * scale) + padding for px in range(xfactor, xfactor + scale):
def draw(self, frame, canvas): p = self.positions[frame] Draw(canvas).ellipse((p[0], p[1], p[0] + self.size[0], p[1] + self.size[1]), fill = self.color)
def imageop(self, op, *args, **keys): t = time.time() image = self.image.copy() op(Draw(image), *args, **keys) self.refresh(image)