def plot_sparkline_discrete(results, args, longlines=False): """The source data is a list of values between 0 and 100 (or 'limits' if given). Values greater than 95 (or 'upper' if given) are displayed in red, otherwise they are displayed in green""" width = int(args.get('width', '2')) height = int(args.get('height', '14')) upper = int(args.get('upper', '50')) below_color = args.get('below-color', 'gray') above_color = args.get('above-color', 'red') gap = 4 if longlines: gap = 0 im = PNGCanvas(len(results)*width-1, height) im.color = rgb.colors['white'] im.filledRectangle(0, 0, im.width-1, im.height-1) (dmin, dmax) = [int(x) for x in args.get('limits', '0,100').split(',')] if dmax < dmin: dmax = dmin zero = im.height - 1 if dmin < 0 and dmax > 0: zero = im.height - (0 - dmin) / (float(dmax - dmin + 1) / (height - gap)) for (r, i) in zip(results, range(0, len(results)*width, width)): color = (r >= upper) and above_color or below_color if r < 0: y_coord = im.height - (r - dmin) / (float(dmax - dmin + 1) / (height - gap)) else: y_coord = im.height - (r - dmin) / (float(dmax - dmin + 1) / (height - gap)) im.color = rgb.colors[color] if longlines: im.filledRectangle(i, zero, i+width-2, y_coord) else: im.rectangle(i, y_coord - gap, i+width-2, y_coord) return im.dump()
def png_sparkline(numbers, width=60, height=14, color=None, bgcolor='white'): if len(numbers) > width: return None color = png_colors.get(color) or png_colors.get('blue') bgcolor = png_colors.get(bgcolor) or png_colors.get('white') img = PNGCanvas(width, height, color=color, bgcolor=bgcolor) img.color = color _draw_series(img, numbers, width, height) return img.dump()
def get(self): # img = PNGCanvas(256, 256) pix = [0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,1,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,1,1,1,1,0,0,0,1,1,1,1,0,0,0,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,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0,0,0,1,1,0,0,1,1,0,0,1,1,0,0,0,0,1,1,0,1,1,0,0,0,0,1,1,0,0,1,1,0,0,1,1,1,0,0,0,1,1,1,0,1,1,0,0,0,0,0,0,0,1,1,0,0,1,0,0,0,0,1,1,0,0,1,1,0,0,1,1,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] krast=5 starp=2 splot = 14 sauks = 14 splot = 9 sauks = 15 istr=int(math.sqrt((splot/2)*(splot/2)+(sauks/2)*(sauks/2))) splot2 = istr*2 sauks2 = istr*2 nn=10 plot=2*krast + nn*splot + (nn-1)*starp auks=2*krast + sauks; plot2=2*krast + nn*splot2 + (nn-1)*starp auks2=2*krast + sauks2; # img = PNGCanvas(plot, auks, [0, 0,0,0]) img = PNGCanvas(plot2, auks2, [0, 0,0,0]) # img = PNGCanvas(plot, auks, [0, 0,0,0]) ss=[0,2,4,6,8,1,3,5,7,9] ss=[0,1,2,3,4,5,6,7,8,9] for i in range(0, 10): sx = ss[i] # sx = random.randrange(0, 10) alfa=((random.randrange(0, 90 , 5)-45)*math.pi)/180 for y in range(1, sauks): # alfa=math.pi/2 # alfa=math.pi/4 alfa=0 for x in range(1, splot): nr = sx*(splot*sauks)+(y-1)*splot+x-1 xcor=x-splot/2 -1 ycor=y-sauks/2-1 istrs=math.sqrt(xcor*xcor+ycor*ycor) # if xcor==0: # if ycor < 0: # alfa1=-math.pi/2 # else: # alfa1=-math.pi/2 # else: alfa1=math.atan2(ycor,xcor) xcornew=istrs*math.cos(alfa1+alfa) ycornew=istrs*math.sin(alfa1+alfa) xx=int(krast+i*(starp+splot2)+splot2/2+1+xcornew) yy=int(krast+sauks2/2+1+ycornew) # xx=krast+i*(starp+splot2)+xcor+splot2/2 +1 # yy=krast+ycor+sauks2/2 +1 if pix[nr]==1: # img.point(xx, yy, [0xff, 0, 0, 0xff]) img.point(xx, yy, [0xff, 0xfa, 0xcd, 0xff]) self.response.headers['Content-Type'] = "image/png" self.response.out.write(img.dump())
def convert_image(self, space_level): tile = PNGCanvas(len(space_level[0]), len(space_level), bgcolor=[0xff,0xff,0xff,0]) color_scheme = [] for i in range(LEVEL_MAX): color_scheme.append(self.color_scheme.canvas[cache_levels[i]][0]) for y in xrange(len(space_level[0])): for x in xrange(len(space_level[0])): tile.canvas[y][x] = color_scheme[int(space_level[y][x])] return tile
def grabImage(): windows = CGWindowListCopyWindowInfo(kCGWindowListOptionAll, kCGNullWindowID) for window in windows: #print(window) try: if window['kCGWindowName'] == 'Krunker': print('Krunker window found!') print(window) # get window dimensions x = int(window['kCGWindowBounds']['X']) y = int(window['kCGWindowBounds']['Y']) width = int(window['kCGWindowBounds']['Width']) height = int(window['kCGWindowBounds']['Height']) print('Dimensions: {}'.format((x, y, width, height))) center = (width // 2, height // 2) print('Center: {}'.format(center)) window_id = int(window['kCGWindowNumber']) print('Window ID: {}'.format(window_id)) #region = CGRectMake(x, y, width, height) #region = CGRectInfinite # get img data img = CGWindowListCreateImage(CGRectInfinite, kCGWindowListOptionAll, window_id, kCGWindowImageDefault) prov = CGImageGetDataProvider(img) img_data = CGDataProviderCopyData(prov) img_width, img_height = CGImageGetWidth(img), CGImageGetHeight( img) # create canvas based on image data pixels canvas = PNGCanvas(img_width, img_height) for x in range(img_width): for y in range(img_height): offset = 4 * ( (img_width * int(round(y))) + int(round(x))) b, g, r, a = struct.unpack_from('BBBB', img_data, offset=offset) canvas.point(x, y, color=(r, g, b, a)) # dump canvas to png with open('test.png', 'wb') as f: f.write(canvas.dump()) except: # handle exception pass
def generate_image(color_value): """根据颜色生成纯色图片,返回图片数据""" width = 300 height = 300 r = color_value[1:3] g = color_value[3:5] b = color_value[5:7] bgcolor=[int(r, 16), int(g, 16), int(b, 16), 0xff] img = PNGCanvas(width, height, bgcolor=bgcolor) return img.dump()
def convert_image(self, space_level): tile = PNGCanvas(len(space_level[0]), len(space_level), bgcolor=[0xff,0xff,0xff,0]) temp_color_scheme = [] for i in range(self.level_max): temp_color_scheme.append(self.color_scheme.canvas[self.cache_levels[i]][0]) for y in xrange(len(space_level[0])): for x in xrange(len(space_level[0])): if len(temp_color_scheme) > 0: tile.canvas[y][x] = [int(e) for e in temp_color_scheme[max(0, min(len(temp_color_scheme) - 1, self.scale_value(space_level[y][x])))]] else: tile.canvas[y][x] = [0,0,0,0] return tile
def convert_image(self, space_level): tile = PNGCanvas(SIZE, SIZE, bgcolor=[0xff,0xff,0xff,0]) temp_color_scheme = [] for i in range(self.level_max): temp_color_scheme.append(self.color_scheme.canvas[self.cache_levels[i]][0]) for y in xrange(SIZE): for x in xrange(SIZE): if len(temp_color_scheme) > 0: tile.canvas[y][x] = [int(e) for e in temp_color_scheme[max(0, min(len(temp_color_scheme) - 1, self.scale_value(space_level[y][x])))]] else: tile.canvas[y][x] = [0,0,0,0] return tile
def convert_image(self, space_level): tile = PNGCanvas(len(space_level[0]), len(space_level), bgcolor=[0xff, 0xff, 0xff, 0]) color_scheme = [] for i in range(LEVEL_MAX): color_scheme.append(self.color_scheme.canvas[cache_levels[i]][0]) for y in xrange(len(space_level[0])): for x in xrange(len(space_level[0])): #log.error(space_level[y][x]) tile.canvas[y][x] = color_scheme[min(LEVEL_MAX - 1, int(space_level[y][x]))] return tile
def create(self): self.img = PNGCanvas(self.width, self.height) self.img.color = [0xff, 0xff, 0xff, 0xff] #self.img.color = [0x39,0x9e,0xff,0xff] #self.img.verticalGradient(1,1,self.width-2, self.height-2,[0xff,0,0,0xff],[0x60,0,0xff,0x80]) self.img.verticalGradient(1, 1, self.width - 2, self.height - 2, [0xff, 0x45, 0x45, 0xff], [0xff, 0xcb, 0x44, 0xff]) for i in range(4): a = str(self.text)[i] self.writeText(a, i) return self.img.dump()
def make_image(self): ''' Creates PNG image with QR Code ''' boxsize = 10 # pixels per box offset = 1 # boxes as border pixelsize = (self.getModuleCount() + offset + offset) * boxsize canvas = PNGCanvas(pixelsize, pixelsize) for row in range(self.getModuleCount()): for column in range(self.getModuleCount()): if (self.isDark(row, column) ): pos_x = (column + offset) * boxsize pos_y = (row + offset) * boxsize canvas.filledRectangle(pos_x, pos_y, pos_x + boxsize, pos_y + boxsize) return canvas.dump()
def make_image(self): """ Creates PNG image with QR Code """ boxsize = 10 # pixels per box offset = 4 # boxes as border pixelsize = (self.getModuleCount() + offset + offset) * boxsize canvas = PNGCanvas(pixelsize, pixelsize) for row in range(self.getModuleCount()): for column in range(self.getModuleCount()): if self.isDark(row, column): pos_x = (column + offset) * boxsize pos_y = (row + offset) * boxsize canvas.filledRectangle(pos_x, pos_y, pos_x + boxsize, pos_y + boxsize) return canvas.dump()
def __init__(self, user, lat_north, lng_west, range_lat, range_lng): userinfo = UserInfo.all().filter('user ='******'t do any more math if we don't have any venues cur_canvas = self.color_scheme.canvas self.tile_img = PNGCanvas(SIZE, SIZE, bgcolor=cur_canvas[len(cur_canvas) - 1][0]) #NOTE the last index should be safe here, but for users with negative level_max's, self.cache_levels was an empty list and thus this was erroring
def create(self): self.img = PNGCanvas(self.width,self.height) self.img.color = [0xff,0xff,0xff,0xff] #self.img.color = [0x39,0x9e,0xff,0xff] #self.img.verticalGradient(1,1,self.width-2, self.height-2,[0xff,0,0,0xff],[0x60,0,0xff,0x80]) self.img.verticalGradient(1,1,self.width-2, self.height-2,[0xff,0x45,0x45,0xff],[0xff,0xcb,0x44,0xff]) for i in range(4): a = str(self.text)[i] self.writeText(a,i) return self.img.dump()
def convert_image(self, space_level): """Given an array containing the pixel-level infromation regarding coverage, this function first builds a color scheme array to correspond to different coverage values, and then fills in a PNG image with the corresponding color values for each coverage value. Essentially this function transforms coverage info into color info""" log.info("Creating png from coverage information") tile = PNGCanvas(len(space_level[0]), len(space_level), bgcolor=[0xff,0xff,0xff,0]) log.debug("Creating color scheme") color_scheme = [] for i in range(LEVEL_MAX): color_scheme.append(self.color_scheme.canvas[cache_levels[i]][0]) log.debug("Color scheme created") for y in xrange(len(space_level[0])): for x in xrange(len(space_level[0])): tile.canvas[y][x] = color_scheme[int(space_level[y][x])] log.info("png created"); return tile
def gdfontstring(self,pic,str,x,y,color): str="%s" % str x=int(x) y=int(y) data=self.__font_data count=self.__font_count start=self.__font_start width=self.__font_width height=self.__font_height z=0 for c in str: codesim=ord(c) for i2 in range(0, height): for i3 in range(0, width): z0=(codesim*width*height+i2*width+i3)*2+32; code=data[z0:(z0+2)] if len(code) == 0: code="0" x0= int(code, 16) if x0>0: PNGCanvas.point(pic,(x+z*width+i3),(y+i2),color) z+=1 return pic
def make_ranking_icon(request, id = None, icon = False): if id or icon: # make the smaller version for display (the id) or for saving to the server width = 80 height = 40 else: width = 200 height = 200 colors = ([0x25, 0x67, 0x79, 0xff], [0xaf, 0xf3, 0x9b, 0xff], [0xed, 0x1e, 0x79, 0xff], [0x29, 0xaa, 0xe2, 0xff], [0x4d, 0x42, 0x4c, 0xff]) weights = request.session.get('source_weights', DefaultWeights) sources_to_aggregate = request.session.get('sources_to_aggregate', DefaultSources) c = PNGCanvas(width,height) num_colors = len(colors) # f = open("/var/www/media/handle.png", "rb") # handle = PNGCanvas(12,12) # handle.load(f) num_sources = len(sources_to_aggregate) if num_sources == 0: return HttpResponse(mimetype='image/png', content=c.dump()) bar_width = width / num_sources half = bar_width / 2 i = 0 for source in sources_to_aggregate: c.color = DataSourceColor.objects.get(datasource=source).color_as_array() #colors[i % num_colors] bar_height = height - height * (weights[source] / 10.0) c.filledRectangle(bar_width * i, bar_height, bar_width * (i + 1) - 1, height) # handle.copyRect(0,0,11,11,10,10,c) #int(bar_height + 6), bar_width * i + half,c) i += 1 if id: f = open("/var/www/media/ranking_icons/icon%d.png" % id, "wb") f.write(c.dump()) f.close() else: return HttpResponse(mimetype='image/png', content=c.dump())
def draw(): from pngcanvas import PNGCanvas import random canvas = PNGCanvas(1000, 1000, bgcolor=(255, 255, 255, 255), color=(0, 0, 0, 255)) circles = [] for _ in range(15): circles.append(Circle(Point(random.randint(0, 1000), random.randint(0, 1000)), random.randint(0, 500))) for circle in circles: for point in circle.get_points(): canvas.point(point.x, point.y, (0x0, 0x0, 0x0, 0xFF)) for left, right in itertools.combinations(circles, 2): for interseption_point in left.intercect_circle_points(right): for p in interseption_point.as_circle(4).get_points(): if p is False or type(p.x) is complex: continue canvas.point(p.x, p.y, (0xff, 0x0, 0x0, 0xff)) with open('circles.png', 'wb') as png: png.write(canvas.dump())
# Unpack data from string into Python'y integers b, g, r, a = struct.unpack_from(data_format, self._data, offset=offset) # Return BGRA as RGBA return (r, g, b, a) def get_screenshot(): sp = ScreenPixel() sp.capture() print(sp.width, sp.height) print(sp.pixel(0, 0)) # 这里是解析像素点色彩 im = Image.frombytes("RGBA", (sp.width, sp.height), sp._data) b, g, r, a = im.split() im = Image.merge("RGBA", (r, g, b, a)) return im if __name__ == "__main__": sp = ScreenPixel() # 设置区域截图(截图区域必须符合1024的规则,不然图像会异常) region = CG.CGRectMake(64, 64, 128, 128) sp.capture(region=region) c = PNGCanvas(sp.width, sp.height) for x in range(sp.width): for y in range(sp.height): c.point(x, y, color = sp.pixel(x, y)) # 这里是保存,如果不需要就可以不用保存,区域越大,保存时间越长 with open("test.png", "wb") as f: f.write(c.dump())
def plot_error(results, args): im = PNGCanvas(40, 15) im.color = rgb.colors['red'] im.line(0, 0, im.width, im.height) im.line(0, im.height, im.width, 0) return im.dump()
def plot_sparkline_smooth(results, args): step = int(args.get('step', '2')) height = int(args.get('height', '20')) (dmin, dmax) = [int(x) for x in args.get('limits', '0,100').split(',')] im = PNGCanvas((len(results)-1)*step+4, height) im.color = rgb.colors['white'] im.filledRectangle(0, 0, im.width-1, im.height-1) coords = zip(range(1,len(results)*step+1, step), [height - 3 - (y-dmin)/(float(dmax - dmin +1)/(height-4)) for y in results]) im.color = [128, 128, 128, 255] lastx, lasty = coords[0] for x0, y0, in coords: im.line(lastx, lasty, x0, y0) lastx, lasty = x0, y0 min_color = rgb.colors[args.get('min-color', 'green')] max_color = rgb.colors[args.get('max-color', 'red')] last_color = rgb.colors[args.get('last-color', 'blue')] has_min = args.get('min-m', 'false') has_max = args.get('max-m', 'false') has_last = args.get('last-m', 'false') if has_min == 'true': min_pt = coords[results.index(min(results))] im.color = min_color im.rectangle(min_pt[0]-1, min_pt[1]-1, min_pt[0]+1, min_pt[1]+1) if has_max == 'true': im.color = max_color max_pt = coords[results.index(max(results))] im.rectangle(max_pt[0]-1, max_pt[1]-1, max_pt[0]+1, max_pt[1]+1) if has_last == 'true': im.color = last_color end = coords[-1] im.rectangle(end[0]-1, end[1]-1, end[0]+1, end[1]+1) return im.dump()
def plot_error(results, args): im = PNGCanvas(40, 15) im.color = rgb.colors('red') im.line(0, 0, im.width-1, im.height-1) im.line(0, im.height-1, im.width-1, 0) return im.dump()
""" Created on Fri Sep 25 17:49:17 2015 @author: pippo """ #!/usr/bin/env python3 from pngcanvas import PNGCanvas import math HEIGHT = 500 WIDTH = int(HEIGHT * (16 / 9)) canvas = PNGCanvas(WIDTH, HEIGHT, bgcolor=(255, 255, 255, 255), color=(0, 0, 0, 255)) def get_point(x, y): """ Return (Red, Green, Blue, Alpha) for the given (x, y) point. """ R = (math.sin(x / 50) ** 2) * 0xFF G = (math.cos(y / 50) ** 2) * 0xFF B = (math.sin((x - y) / 50) ** 2) * 0xFF A = 0xFF return (int(R), int(G), int(B), int(A)) for x in range(WIDTH): for y in range(HEIGHT):
class Image(): text = None md5Text = None img = None width = 0 height = 0 #长度 textX = 10 textY = 10 beginX = 5 endX = 5 beginY = 5 endY = 5 spare = 4 def __init__(self, text=None): if (text == None): self.text = self.getRandom() else: self.text = text #self.getMd5Text() self.width = len(str( self.text)) * (self.spare + self.textX) + self.beginX + self.endX self.height = self.textY + self.beginY + self.endY def create(self): self.img = PNGCanvas(self.width, self.height) self.img.color = [0xff, 0xff, 0xff, 0xff] #self.img.color = [0x39,0x9e,0xff,0xff] #self.img.verticalGradient(1,1,self.width-2, self.height-2,[0xff,0,0,0xff],[0x60,0,0xff,0x80]) self.img.verticalGradient(1, 1, self.width - 2, self.height - 2, [0xff, 0x45, 0x45, 0xff], [0xff, 0xcb, 0x44, 0xff]) for i in range(4): a = str(self.text)[i] self.writeText(a, i) return self.img.dump() def getRandom(self): intRand = random.randrange(1000, 9999) return intRand def getMd5Text(self): m = md5.new() m.update(str(self.text)) self.md5Text = m.hexdigest() def writeText(self, text, pos=0): if (text == "1"): self.writeLine(pos, "avc") elif (text == "2"): self.writeLine(pos, "aht") self.writeLine(pos, "hvtr") self.writeLine(pos, "ahc") self.writeLine(pos, "hvbl") self.writeLine(pos, "ahb") elif (text == "3"): self.writeLine(pos, "aht") self.writeLine(pos, "ahc") self.writeLine(pos, "ahb") self.writeLine(pos, "avr") elif (text == "4"): self.writeLine(pos, "hvtl") self.writeLine(pos, "ahc") self.writeLine(pos, "avc") elif (text == "5"): self.writeLine(pos, "aht") self.writeLine(pos, "hvtl") self.writeLine(pos, "ahc") self.writeLine(pos, "hvbr") self.writeLine(pos, "ahb") elif (text == "6"): self.writeLine(pos, "aht") self.writeLine(pos, "avl") self.writeLine(pos, "ahc") self.writeLine(pos, "hvbr") self.writeLine(pos, "ahb") elif (text == "7"): self.writeLine(pos, "aht") self.writeLine(pos, "avr") elif (text == "8"): self.writeLine(pos, "aht") self.writeLine(pos, "avl") self.writeLine(pos, "ahc") self.writeLine(pos, "avr") self.writeLine(pos, "ahb") elif (text == "9"): self.writeLine(pos, "aht") self.writeLine(pos, "avr") self.writeLine(pos, "ahc") self.writeLine(pos, "ahb") self.writeLine(pos, "hvtl") elif (text == "0"): self.writeLine(pos, "aht") self.writeLine(pos, "avl") self.writeLine(pos, "avr") self.writeLine(pos, "ahb") ''' type解释 a:全部,部分上下 h:一半 h:横 v:竖 l:左,上 c:中间 r:右,下 t:上 b:下 ''' def writeLine(self, pos, type): if (type == "avl"): self.img.line(self.beginX + (self.textX + self.spare) * pos, self.beginY, self.beginX + (self.textX + self.spare) * pos, self.beginY + self.textY) elif (type == "avc"): self.img.line( self.beginX + (self.textX + self.spare) * pos + self.textX / 2, self.beginY, self.beginX + (self.textX + self.spare) * pos + self.textX / 2, self.beginY + self.textY) elif (type == "avr"): self.img.line( self.beginX + (self.textX + self.spare) * pos + self.textX, self.beginY, self.beginX + (self.textX + self.spare) * pos + self.textX, self.beginY + self.textY) elif (type == "aht"): self.img.line( self.beginX + (self.textX + self.spare) * pos, self.beginY, self.beginX + (self.textX + self.spare) * pos + self.textX, self.beginY, ) elif (type == "ahc"): self.img.line( self.beginX + (self.textX + self.spare) * pos, self.beginY + self.textY / 2, self.beginX + (self.textX + self.spare) * pos + self.textX, self.beginY + self.textY / 2) elif (type == "ahb"): self.img.line( self.beginX + (self.textX + self.spare) * pos, self.beginY + self.textY, self.beginX + (self.textX + self.spare) * pos + self.textX, self.beginY + self.textY) elif (type == "hvtl"): self.img.line(self.beginX + (self.textX + self.spare) * pos, self.beginY, self.beginX + (self.textX + self.spare) * pos, self.beginY + self.textY / 2) elif (type == "hvtr"): self.img.line( self.beginX + (self.textX + self.spare) * pos + self.textX, self.beginY, self.beginX + (self.textX + self.spare) * pos + self.textX, self.beginY + self.textY / 2) elif (type == "hvbl"): self.img.line(self.beginX + (self.textX + self.spare) * pos, self.beginY + self.textY / 2, self.beginX + (self.textX + self.spare) * pos, self.beginY + self.textY) elif (type == "hvbr"): self.img.line( self.beginX + (self.textX + self.spare) * pos + self.textX, self.beginY + self.textY / 2, self.beginX + (self.textX + self.spare) * pos + self.textX, self.beginY + self.textY)
def cont(self,req,modname,rparameters): param=urlparam(rparameters) ext=param['ext'] lang=param['lang'] aps=param['aps'] kalb=param['kalb'] lang1 = gettext.translation (cmstrans2, locale_path, [kalb] , fallback=True) _ = lang1.ugettext modname2 = 'custommodule' if not req.request.get('cmd'): page = Page.loadnew(modname2) greeting = '' bio_cgi_url = "/bioview" bio_cgi_url = ("%s/%s-mo2%s-%s.%s" % (urlhost2(), cmspath2,modname,lang, fileext)) gimmet='' gimmen='' gimdien='' simbsafe = re.compile("[^0-9a-zA-Z]") mazosios = re.compile("[^a-z]") skaic = re.compile("[^0-9]") handler = {} if 'HTTP_COOKIE' in os.environ: cookies = os.environ['HTTP_COOKIE'] cookies = cookies.split('; ') for cookie in cookies: cookie = cookie.split('=') handler[cookie[0]] = cookie[1] if 'terebasGimd' in handler: gimd = handler['terebasGimd'] gimd = "%s" % (skaic.sub("", gimd)) try: gimmet=gimd[0,4] gimmen=gimd[4,6] gimdien=gimd[6,8] except: zerr = True unixtime=time.time() d = datetime.datetime.fromtimestamp(unixtime) lang = req.request.get('lang') or 'lt' gimmet = req.request.get('gmet') or gimmet gimmen = req.request.get('gmem') or gimmen gimdien = req.request.get('gdien') or gimdien siemet = req.request.get('smet') or d.strftime('%Y') men = req.request.get('men') or d.strftime('%m') biohtml='' if not lang: lang = 'lt' else: lang = mazosios.sub("", lang) if not gimmet: gimmet = '1970' else: gimmet = skaic.sub("", gimmet) if not gimmen: gimmen = '06' else: gimmen = skaic.sub("", gimmen) if not gimdien: gimdien = '20' else: gimdien = skaic.sub("", gimdien) if not siemet: format = '%Y' siemet = d.strftime(format) else: siemet = skaic.sub("", siemet) if not men: format = '%m' men = d.strftime(format) else: men = skaic.sub("", men) if req.request.get('gmet') and req.request.get('gmem') and req.request.get('gdien'): bioduom = "lang="+lang+"&gmet="+gimmet+"&gmem="+gimmen+"&gdien="+gimdien+"&smet="+siemet+"&men="+men biohtml = "<img src=\""+bio_cgi_url+"?cmd=1&"+bioduom+"\" height=\"256\" width=\"256\" alt=\"\" />\n" template_values2 = { 'biohtml': biohtml, 'gimmet': gimmet, 'gimmen': gimmen, 'gimdien': gimdien, 'siemet': siemet, 'men': men } directory = os.path.dirname(__file__) path = os.path.join(directory, "bio.html") cont1 = template.render(path, template_values2, debug=_DEBUG) page.content = cont1 page_name2 = 'menu'+'-'+lang+'.'+fileext page2 = Page.load(page_name2) page3 = Page.loadnew("kalbos") textaps='' if len(aps)>0: textaps=aps+'.' text='' for name, value in kalbossort: text = text + (_kalbhtml % ('mo2'+modname, textaps+name, ext, name, name)) page3.content = text req.generate('view.html', lang, { 'imgshar': False, 'noedit': '1', 'application_name': siteauth(), 'kalbos': page3, 'menu': page2, 'page': page, }) elif req.request.get('cmd') == '1': unixtime=time.time() d = datetime.datetime.fromtimestamp(unixtime) lang = req.request.get('lang') or 'lt' gimmet = req.request.get('gmet') or '1970' gimmen = req.request.get('gmem') or '06' gimdien = req.request.get('gdien') or '20' siemet = req.request.get('smet') or d.strftime('%Y') men = req.request.get('men') or d.strftime('%m') simbsafe = re.compile("[^0-9a-zA-Z]") mazosios = re.compile("[^a-z]") skaic = re.compile("[^0-9]") if not lang: lang = 'lt' else: lang = mazosios.sub("", lang) if not gimmet: gimmet = '1970' else: gimmet = skaic.sub("", gimmet) if not gimmen: gimmen = '06' else: gimmen = skaic.sub("", gimmen) if not gimdien: gimdien = '20' else: gimdien = skaic.sub("", gimdien) if not siemet: format = '%Y' siemet = d.strftime(format) else: siemet = skaic.sub("", siemet) if not men: format = '%m' men = d.strftime(format) else: men = skaic.sub("", men) format = '%H:%i:%s %m/%d/%Y %O' date = d.strftime(format) if lang == 'en': bio_new = 'bio_en8.png' strbio = "Biorhythms" strfiz = "Physical State" stremo = "Emotional State" strint = "Intellect" strmd = "Days of the Month" strid = "Survived Days" strgd = "Date of Birth" strm = "Month" else: bio_new = 'bio_lt8.png' strbio = "Bioritmai" strfiz = "Fizin\xEB bukl\xEB" stremo = "Emocin\xEB b\xFBsena" strint = "Intelektas" strmd = "Menesio dienos" strid = "I\xF0gyventa dien\xF8" strgd = "Gimimo data" strm = "M\xEBnuo" bio_new = '1m.png' color1 = [106, 0,0,0] color2 = [0xff, 0xff, 0, 0xff] color3 = [128, 255, 0, 0xff] color4 = [0,128,255, 0xff] color5 = [255,128,255, 0xff] color6 = [255,255,0, 0xff] color1 = [0x00, 0x30,0xd2,0xFF] color2 = [0xf6, 0xf3, 0x00, 0xff] color3 = [0xfe, 0x7f, 0xfe, 0xff] color4 = [0x7f, 0xfe, 0x00, 0xff] color5 = [255,128,255, 0xff] color6 = [255,255,0, 0xff] color1 = [0xAC, 0x2F,0x93,0xFF] color1 = [0x00, 0x00,0x8e,0xFF] color2 = [0xCA, 0x45, 0x46, 0xff] color3 = [0xd3, 0xa5, 0x6a, 0xff] color4 = [0x71, 0xa4, 0xcf, 0xff] color5 = [0xfd, 0xd9, 0x13, 0xff] color1 = [0x00, 0x00,0x8e,0xFF] color2 = [0x2b, 0xf6, 0x42, 0xff] color3 = [0xfc, 0xf1, 0x33, 0xff] color4 = [0xf8, 0x01, 0xd6, 0xff] color5 = [0xff, 0x0e, 0x06, 0xff] color6 = [255,255,0, 0xff] #f6f300 #fe7ffe #000000 #7ffe00 #0030d2 #00008e - fonas melyna # ff0e06 raud #2bf642 zalia #fcf133 gel #f801d6 viol cikfiz = 23 cikemo = 28 cikint = 33 ilg = [0,31,28,31,30,31,30,31,31,30,31,30,31] ys=0 derr = False if gimmet<1970: ys=1970-int(gimmet) try: year=int(gimmet)+ys tt1 = datetime.date(int(year), int(gimmen), int(gimdien)) year=int(siemet)+ys tt2 = datetime.date(int(year), int(men), 1) t1=time.mktime(tt1.timetuple()) t2=time.mktime(tt2.timetuple()) dienu=int((int(t2)-int(t1))/86400) except: derr = True # errtext = cgi.escape(str(sys.exc_info()[0])) + ' ' + cgi.escape(str(sys.exc_info()[1])) + ' ' + cgi.escape(str(sys.exc_info()[2])) # req.response.out.write(errtext) # sys.exit(0) if derr: dienu=0 ref=False if 'HTTP_REFERER' in os.environ: for referer in referers: pos = os.environ['HTTP_REFERER'].find(referer) # The offset is optional if not(pos < 0): # not found ref = True else: ref = True if not ref: #if uselog: #log() width = 256 height = 256 im = PNGCanvas(256, 256, [255, 255,255,255]) im.color = [0xff,0,0,0xff] im.rectangle(0,0,width-1,height-1) im.verticalGradient(1,1,width-2, height-2,[0xff,0,0,0xff],[0x20,0,0xff,0x80]) im.color = [0,0,0,0xff] im.line(0,0,width-1,height-1) im.line(0,0,width/2,height-1) im.line(0,0,width-1,height/2) im.copyRect(1,1,width/2-1,height/2-1,0,height/2,im) im.blendRect(1,1,width/2-1,height/2-1,width/2,0,im) str = "Bad referer" y = 5 x = 256 / 2 - len(str) * 9 / 2 x = "%u" % x font=GDFont() font.load( 'giant_w57.gd','gdfonts') im=GDFont.gdfontstring(font,im,str,x,y,[0, 0, 0, 0xff]) else: zerr=False im = False try: directory = os.path.dirname(__file__) path = os.path.join(directory, os.path.join('gdfonts', bio_new)) imghex=file(path,'rb').read() f = cStringIO.StringIO(imghex) im = PNGCanvas(256, 256, [0, 0,0,0]) im.load(f) except: zerr = True if zerr: # im = PNGCanvas(256, 256, [0, 0,0,0]) im = PNGCanvas(256, 256, color1) zerr=True str = strbio y = 10 x = 256 / 2 - len(str) * 9 / 2 x = "%u" % x font5=GDFont() font5.load( 'giant_w57.gd','gdfonts') font4=GDFont() font4.load( 'large_w57.gd','gdfonts') font3=GDFont() font3.load( 'medium_w57.gd','gdfonts') font2=GDFont() font2.load( 'small_w57.gd','gdfonts') font1=GDFont() font1.load( 'tiny_w57.gd','gdfonts') if zerr: im=GDFont.gdfontstring(font5,im,str,x,y,color2) str = strfiz y = 130 + 10 x = 256 / 2 - len(str) * 6 / 2 x = "%u" % x if zerr: im=GDFont.gdfontstring(font2,im,str,x,y,color3) str = stremo y = 130 + 10 + 5 + 12 x = 256 / 2 - len(str) * 6 / 2 x = "%u" % x if zerr: im=GDFont.gdfontstring(font2,im,str,x,y,color4) str = strint y = 130 + 10 + 5 + 12 + 5 + 12 x = 256 / 2 - len(str) * 6 / 2 x = "%u" % x if zerr: im=GDFont.gdfontstring(font2,im,str,x,y,color5) str = strmd y = 82 + 4 + 8 + 4 x = 256 / 2 - len(str) * 5 / 2 x = "%u" % x if zerr: im=GDFont.gdfontstring(font1,im,str,x,y,color2) str = strid+':' y = 130 + 10 + 5 + 12 + 5 + 12 + 5 + 12 x = 256 / 2 - len(str) * 6 x = "%u" % x if zerr: im=GDFont.gdfontstring(font2,im,str,x,y,color2) str = " %s" % dienu y = 130 + 10 + 5 + 12 + 5 + 12 + 5 + 12 x = 256 / 2 x = "%u" % x im=GDFont.gdfontstring(font2,im,str,x,y,color2) str = strgd+':' y = 130 + 10 + 5 + 12 + 5 + 12 + 5 + 12 + 8 + 12 x = 256 / 2 - len(str) * 7 x = "%u" % x if zerr: im=GDFont.gdfontstring(font3,im,str,x,y,color2) str = " %s/%s/%s" % (gimmet, gimmen, gimdien) y = 130 + 10 + 5 + 12 + 5 + 12 + 5 + 12 + 8 + 12 x = 256 / 2 x = "%u" % x im=GDFont.gdfontstring(font3,im,str,x,y,color2) str = strm+':' y = 130 + 10 + 5 + 12 + 5 + 12 + 5 + 12 + 8 + 12 + 6 + 13 x = 256 / 2 - len(str) * 7 x = "%u" % x if zerr: im=GDFont.gdfontstring(font3,im,str,x,y,color2) str = " %s/%s" % (siemet,men) y = 130 + 10 + 5 + 12 + 5 + 12 + 5 + 12 + 8 + 12 + 6 + 13 x = 256 / 2 x = "%u" % x im=GDFont.gdfontstring(font3,im,str,x,y,color2) prad = 10 gal = 256 - prad im.color = color2 im.line(prad,80,gal,80) ii = ilg[int(men)] if int(men) == 2 and int(int(siemet) % 4) == 0: ii+=1 y = 82 + 4 str = 1 x = prad - len("%s" % str) * 5 / 2 x = "%u" % x im=GDFont.gdfontstring(font1,im,str,x,y,color2) for i in range(5, ii, 5): str = i x = prad + (i - 1) * (256 - prad - prad) / (ii - 1) x = x - len("%s" % str) * 5 / 2 x = "%u" % x im=GDFont.gdfontstring(font1,im,str,x,y,color2) pi = math.pi x = prad xsen = "%u" % x y = 80 - 50 * math.sin((1 + dienu) * 2 * pi / cikfiz) yfiz = "%u" % y y = 80 - 50 * math.sin((1 + dienu) * 2 * pi / cikemo) yemo = "%u" % y y = 80 - 50 * math.sin((1 + dienu) * 2 * pi / cikint) yint = "%u" % y for i in range(1, ii): x = prad + (i - 1) * (256 - prad - prad) / (ii - 1) x = "%u" % x im.color = color2 im.line(x,78,x,82) y = 80 - 50 * math.sin((i + dienu) * 2 * pi / cikfiz) y = "%u" % y im.color = color3 im.line(xsen,yfiz,x,y) yfiz = y y = 80 - 50 * math.sin((i + dienu) * 2 * pi / cikemo) y = "%u" % y im.color = color4 im.line(xsen,yemo,x,y) yemo = y y = 80 - 50 * math.sin((i + dienu) * 2 * pi / cikint) y = "%u" % y im.color = color5 im.line(xsen,yint,x,y) yint = y xsen = x sgimmet = "%04d" % int(gimmet) sgimmen = "%02d" % int(gimmen) sgimdien = "%02d" % int(gimdien) gimd=sgimmet+sgimmen+sgimdien expiration = datetime.datetime.now() + timedelta(seconds=3600*24*90) exp=expiration.strftime("%a, %d-%b-%Y %H:%M:%S PST") req.response.headers['Content-Type'] = "image/png" req.response.headers['Set-Cookie'] = "terebasGimd=%s; path=/; expires=%s" % (gimd,exp) req.response.out.write(im.dump())
self.width = CG.CGImageGetWidth(image) self.height = CG.CGImageGetHeight(image) def pixel(self, x, y): data_format = "BBBB" offset = 4 * ((self.width*int(round(y))) + int(round(x))) b, g, r, a = struct.unpack_from(data_format, self._data, offset=offset) return (r, g, b, a) if __name__ == '__main__': sp = ScreenPixel() region = CG.CGRectMake(242, 440, 400, 400) sp.capture(region=region) print sp.width, sp.height print sp.pixel(0, 0) from pngcanvas import PNGCanvas c = PNGCanvas(sp.width, sp.height) for x in range(sp.width): for y in range(sp.height): c.point(x, y, color = sp.pixel(x, y)) with open("test.png", "wb") as f: f.write(c.dump())
class BasicTile(object): def __init__(self, user, lat_north, lng_west, range_lat, range_lng): userinfo = UserInfo.all().filter('user ='******'t do any more math if we don't have any venues cur_canvas = self.color_scheme.canvas self.tile_img = PNGCanvas(SIZE, SIZE, bgcolor=cur_canvas[len(cur_canvas) - 1][0]) #NOTE the last index should be safe here, but for users with negative level_max's, self.cache_levels was an empty list and thus this was erroring def plot_image(self, points): space_level = self.__create_empty_space() rad = int(self.zoom * DOT_MULT) start = datetime.now() for i, point in enumerate(points): self.__merge_point_in_space(space_level, point, rad) # logging.debug(' point %d of %d, start at %s, done at %s' % (i, len(points), start, datetime.now())) return self.convert_image(space_level) def __merge_point_in_space(self, space_level, point, rad): weight = len(point.checkin_guid_list) rad_exp = math.pow(weight, 0.25) alpha_weight = MAX_ALPHA * weight twice_rad = rad * 2 y_off = int(math.ceil((-1 * self.northwest_ll[0] + point.location.lat) / self.latlng_diff[0] * 256. - rad)) x_off = int(math.ceil((-1 * self.northwest_ll[1] + point.location.lon) / self.latlng_diff[1] * 256. - rad)) for y in range(y_off, y_off + twice_rad): if y < 0 or y >= SIZE: continue y_adj = math.pow((y - rad - y_off), 2) for x in range(x_off, x_off + twice_rad): if x < 0 or x >= SIZE: continue x_adj = math.pow((x - rad - x_off), 2) pt_rad = math.sqrt(y_adj + x_adj) if pt_rad > rad: continue space_level[y][x] += (math.pow((rad - pt_rad) / rad, rad_exp) * alpha_weight) def scale_value(self, value): #ret_float = math.log(max((value + 50) / 50, 1), 1.01) + 30 #ret_float = math.log(max((value + 30) / 40, 1), 1.01) + 30 #ret_float = math.log(max((value + 40) / 20, 1), 1.01) ret_float = math.log(max(value, 1), 1.1) * 4 return int(ret_float) def convert_image(self, space_level): tile = PNGCanvas(SIZE, SIZE, bgcolor=[0xff,0xff,0xff,0]) temp_color_scheme = [] for i in range(self.level_max): temp_color_scheme.append(self.color_scheme.canvas[self.cache_levels[i]][0]) for y in xrange(SIZE): for x in xrange(SIZE): if len(temp_color_scheme) > 0: tile.canvas[y][x] = [int(e) for e in temp_color_scheme[max(0, min(len(temp_color_scheme) - 1, self.scale_value(space_level[y][x])))]] else: tile.canvas[y][x] = [0,0,0,0] return tile def __create_empty_space(self): space = [] for i in range(SIZE): space.append( [0.] * SIZE ) return space def image_out(self): if self.tile_img: self.tile_dump = self.tile_img.dump() if self.tile_dump: return self.tile_dump else: raise Exception("Failure in generation of image.")
def plot_sparkline_discrete(results, args, longlines=False): """The source data is a list of values between 0 and 100 (or 'limits' if given). Values greater than 95 (or 'upper' if given) are displayed in red, otherwise they are displayed in green""" width = int(args.get('width', '2')) height = int(args.get('height', '14')) upper = int(args.get('upper', '50')) below_color = args.get('below-color', 'gray') above_color = args.get('above-color', 'red') gap = 4 if longlines: gap = 0 im = PNGCanvas(len(results) * width - 1, height) im.color = rgb.colors['white'] im.filledRectangle(0, 0, im.width - 1, im.height - 1) (dmin, dmax) = [int(x) for x in args.get('limits', '0,100').split(',')] if dmax < dmin: dmax = dmin zero = im.height - 1 if dmin < 0 and dmax > 0: zero = im.height - (0 - dmin) / (float(dmax - dmin + 1) / (height - gap)) for (r, i) in zip(results, range(0, len(results) * width, width)): color = (r >= upper) and above_color or below_color if r < 0: y_coord = im.height - (r - dmin) / (float(dmax - dmin + 1) / (height - gap)) else: y_coord = im.height - (r - dmin) / (float(dmax - dmin + 1) / (height - gap)) im.color = rgb.colors[color] if longlines: im.rectangle(i, zero, i + width - 2, y_coord) else: im.rectangle(i, y_coord - gap, i + width - 2, y_coord) return im.dump()
# -*- coding: utf-8 -*- """ Created on 2014-09- Last edited on 2014-09- @author: Ew3n """ from pngcanvas import PNGCanvas import math HEIGHT = 500 WIDTH = int(HEIGHT * (16 / 9)) canvas = PNGCanvas(WIDTH, HEIGHT, bgcolor=(255, 255, 255, 255), color=(0, 0, 0, 255)) def get_point(x, y): """ Return (Red, Green, Blue, Alpha) for the given (x, y) point. """ R = (math.sin(x / 50)**2) * 0xFF G = (math.cos(y / 50)**2) * 0xFF B = (math.sin((x - y) / 50)**2) * 0xFF A = 0xFF return (int(R), int(G), int(B), int(A)) for x in range(WIDTH):
class Image(): text = None md5Text = None img = None width = 0 height = 0 #长度 textX = 10 textY = 10 beginX = 5 endX = 5 beginY = 5 endY = 5 spare = 4 def __init__(self,text=None): if(text==None): self.text = self.getRandom() else: self.text = text #self.getMd5Text() self.width = len(str(self.text))*(self.spare+self.textX)+self.beginX+self.endX self.height = self.textY + self.beginY + self.endY def create(self): self.img = PNGCanvas(self.width,self.height) self.img.color = [0xff,0xff,0xff,0xff] #self.img.color = [0x39,0x9e,0xff,0xff] #self.img.verticalGradient(1,1,self.width-2, self.height-2,[0xff,0,0,0xff],[0x60,0,0xff,0x80]) self.img.verticalGradient(1,1,self.width-2, self.height-2,[0xff,0x45,0x45,0xff],[0xff,0xcb,0x44,0xff]) for i in range(4): a = str(self.text)[i] self.writeText(a,i) return self.img.dump() def getRandom(self): intRand = random.randrange(1000,9999) return intRand def getMd5Text(self): m = md5.new() m.update(str(self.text)) self.md5Text = m.hexdigest() def writeText(self,text,pos=0): if(text=="1"): self.writeLine(pos, "avc") elif(text=="2"): self.writeLine(pos, "aht") self.writeLine(pos, "hvtr") self.writeLine(pos, "ahc") self.writeLine(pos, "hvbl") self.writeLine(pos, "ahb") elif(text=="3"): self.writeLine(pos, "aht") self.writeLine(pos, "ahc") self.writeLine(pos, "ahb") self.writeLine(pos, "avr") elif(text=="4"): self.writeLine(pos, "hvtl") self.writeLine(pos, "ahc") self.writeLine(pos, "avc") elif(text=="5"): self.writeLine(pos, "aht") self.writeLine(pos, "hvtl") self.writeLine(pos, "ahc") self.writeLine(pos, "hvbr") self.writeLine(pos, "ahb") elif(text=="6"): self.writeLine(pos, "aht") self.writeLine(pos, "avl") self.writeLine(pos, "ahc") self.writeLine(pos, "hvbr") self.writeLine(pos, "ahb") elif(text=="7"): self.writeLine(pos, "aht") self.writeLine(pos, "avr") elif(text=="8"): self.writeLine(pos, "aht") self.writeLine(pos, "avl") self.writeLine(pos, "ahc") self.writeLine(pos, "avr") self.writeLine(pos, "ahb") elif(text=="9"): self.writeLine(pos, "aht") self.writeLine(pos, "avr") self.writeLine(pos, "ahc") self.writeLine(pos, "ahb") self.writeLine(pos, "hvtl") elif(text=="0"): self.writeLine(pos, "aht") self.writeLine(pos, "avl") self.writeLine(pos, "avr") self.writeLine(pos, "ahb") ''' type解释 a:全部,部分上下 h:一半 h:横 v:竖 l:左,上 c:中间 r:右,下 t:上 b:下 ''' def writeLine(self,pos,type): if(type=="avl"): self.img.line( self.beginX+(self.textX+self.spare)*pos, self.beginY, self.beginX+(self.textX+self.spare)*pos, self.beginY+self.textY ) elif(type=="avc"): self.img.line( self.beginX+(self.textX+self.spare)*pos+self.textX/2, self.beginY, self.beginX+(self.textX+self.spare)*pos+self.textX/2, self.beginY+self.textY ) elif(type=="avr"): self.img.line( self.beginX+(self.textX+self.spare)*pos+self.textX, self.beginY, self.beginX+(self.textX+self.spare)*pos+self.textX, self.beginY+self.textY ) elif(type=="aht"): self.img.line( self.beginX+(self.textX+self.spare)*pos, self.beginY, self.beginX+(self.textX+self.spare)*pos+self.textX, self.beginY, ) elif(type=="ahc"): self.img.line( self.beginX+(self.textX+self.spare)*pos, self.beginY+self.textY/2, self.beginX+(self.textX+self.spare)*pos+self.textX, self.beginY+self.textY/2 ) elif(type=="ahb"): self.img.line( self.beginX+(self.textX+self.spare)*pos, self.beginY+self.textY, self.beginX+(self.textX+self.spare)*pos+self.textX, self.beginY+self.textY ) elif(type=="hvtl"): self.img.line( self.beginX+(self.textX+self.spare)*pos, self.beginY, self.beginX+(self.textX+self.spare)*pos, self.beginY+self.textY/2 ) elif(type=="hvtr"): self.img.line( self.beginX+(self.textX+self.spare)*pos+self.textX, self.beginY, self.beginX+(self.textX+self.spare)*pos+self.textX, self.beginY+self.textY/2 ) elif(type=="hvbl"): self.img.line( self.beginX+(self.textX+self.spare)*pos, self.beginY+self.textY/2, self.beginX+(self.textX+self.spare)*pos, self.beginY+self.textY ) elif(type=="hvbr"): self.img.line( self.beginX+(self.textX+self.spare)*pos+self.textX, self.beginY+self.textY/2, self.beginX+(self.textX+self.spare)*pos+self.textX, self.beginY+self.textY )
def plot_error(results, args): im = PNGCanvas(40, 15) im.color = rgb.colors['red'] im.line(0, 0, im.width - 1, im.height - 1) im.line(0, im.height - 1, im.width - 1, 0) return im.dump()
#!/usr/bin/python # Gets partial screenshot and saves it into PNG file. import Quartz.CoreGraphics as cg region = cg.CGRectMake( 0, 0, 400, 400) # You can also use cg.CGRectInfinite for the full screen. image = cg.CGWindowListCreateImage(region, cg.kCGWindowListOptionOnScreenOnly, cg.kCGNullWindowID, cg.kCGWindowImageDefault) prov = cg.CGImageGetDataProvider(image) img_data = cg.CGDataProviderCopyData(prov) img_width, img_height = cg.CGImageGetWidth(image), cg.CGImageGetHeight(image) from pngcanvas import PNGCanvas import struct canvas = PNGCanvas(img_width, img_height) for x in range(img_width): for y in range(img_height): # Calculate offset, based on http://www.markj.net/iphone-uiimage-pixel-color/ offset = 4 * ((img_width * int(round(y))) + int(round(x))) # Pixel data is unsigned char (8bit unsigned integer), and there are for (blue,green,red,alpha). # Unpack data from string into Python'y integers. b, g, r, a = struct.unpack_from("BBBB", img_data, offset=offset) # Assign BGRA color as RGBA. canvas.point(x, y, color=(r, g, b, a)) with open("test.png", "wb") as f: f.write(canvas.dump())
def plot_sparkline_smooth(results, args): step = int(args.get('step', '2')) height = int(args.get('height', '20')) (dmin, dmax) = [int(x) for x in args.get('limits', '0,100').split(',')] im = PNGCanvas((len(results) - 1) * step + 4, height) im.color = rgb.colors['white'] im.filledRectangle(0, 0, im.width - 1, im.height - 1) coords = zip(range(1, len(results) * step + 1, step), [ height - 3 - (y - dmin) / (float(dmax - dmin + 1) / (height - 4)) for y in results ]) im.color = rgb.colors['gray'] lastx, lasty = coords[0] for x0, y0, in coords: im.line(lastx, lasty, x0, y0) lastx, lasty = x0, y0 min_color = rgb.colors[args.get('min-color', 'green')] max_color = rgb.colors[args.get('max-color', 'red')] last_color = rgb.colors[args.get('last-color', 'blue')] has_min = args.get('min-m', 'false') has_max = args.get('max-m', 'false') has_last = args.get('last-m', 'false') if has_min == 'true': min_pt = coords[results.index(min(results))] im.color = min_color im.rectangle(min_pt[0] - 1, min_pt[1] - 1, min_pt[0] + 1, min_pt[1] + 1) if has_max == 'true': im.color = max_color max_pt = coords[results.index(max(results))] im.rectangle(max_pt[0] - 1, max_pt[1] - 1, max_pt[0] + 1, max_pt[1] + 1) if has_last == 'true': im.color = last_color end = coords[-1] im.rectangle(end[0] - 1, end[1] - 1, end[0] + 1, end[1] + 1) return im.dump()
def get(self): # f = open("ttt.zip", "rb") bio1_b64 = \ """iVBORw0KGgoAAAANSUhEU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B1M2wAdSdsAHUbbAB1D2wAfZLALqXA7QuDehbJtC0ZKBj+UC7UoJe ZQWNSgy6lBu0KD3oT4bQnCShM3lCW1KFnmQLDUkYupEztCJt6EPm0ITkoQP5Q/pagNx1AYlrBLLW C6SsHchXR5CspiBTfUGaWoMcdQcJalB20KPUoE15QaeSgmZlBP1KB1qWC3QtEWhcFtC7FKB994MD LgcT3Aw+uBascCe44UIwxG3giavAFveAMy4Bc9wA/vj0YJHPDS6xH4xiP3jFfrCL/eAY+8E09oNv 7Afr2A/usR9lA9mP7gbYj+4G2I/uBtiP7gbYj+4G2I/uBtiP7gbYj+4G2I/uBtiP7gbYj+4G2I/u BtiP7gbYj+4G2I/uBtiP7gbYj+4G2I/uBtiP7gbYj+wGHstS6mBKh9nJAAAAAElFTkSuQmCC """ imghex=base64.decodestring(bio1_b64) f = cStringIO.StringIO(imghex) # f=cStringIO.StringIO() # f.write(img) # img = PNGCanvas(256, 256) img = PNGCanvas(256, 256, [0, 0,0,0]) img.load(f) f.close() font=GDFont() font.load( 'giant_w57.gd','gdfonts') img=GDFont.gdfontstring(font,img,"Bioritmai",5,5,[0xff, 0xff, 0, 0xff]) font2=GDFont() font2.load( 'medium_w57.gd','gdfonts') img=GDFont.gdfontstring(font2,img,"ABCabc",5,25,[0xff, 0xff, 0, 0xff]) for i in range(0, 256): img.point(i, i, [0xff, 0, 0, 0xff]) ii = 256 - i img.point(ii, i, [0xff, 0, 0, 0xff]) img.point(122, i, [0xff, 0, 0, 0xff]) img.point(126, i, [0xff, 0, 0, 0xff]) img.point(130, i, [0xff, 0, 0, 0xff]) img.point(134, i, [0xff, 0, 0, 0xff]) img.point(i, 122, [0xff, 0, 0, 0xff]) img.point(i, 126, [0xff, 0, 0, 0xff]) img.point(i, 130, [0xff, 0, 0, 0xff]) img.point(i, 134, [0xff, 0, 0, 0xff]) self.response.headers['Content-Type'] = "image/png" self.response.out.write(img.dump())