def dummy_image(self, width, height): d = self._get_dummy_image_data(width, height) im = Image(Geometry(width, height), Color(*d['canvas_color'])) im.strokeColor(Color(*d['line_color'])) im.strokeWidth(1) for line in d['lines']: im.draw(DrawableLine(*line)) im.fillColor(Color()) im.draw(DrawableRectangle(*d['rectangle'])) return im
def buildNodeImage(self,node): self.buildCounterNode+=1 node['name'] = node['name'].encode("utf-8") print "{0:.2f}".format(self.buildCounterNode / (self.buildCounterNodeTotal) * 100)," percent complete of this batch \r", scale = self.scaleFactor #if node['size'] > 10: #cale = 4.75 #if node['size'] < 900: # scale = 4 circleHeight = int(float(node['size'])*scale) circleWidth = int(float(node['size'])*scale) canvasHeight = int(circleHeight *2) canvasWidth = int(circleWidth* 2) im = Image(Geometry(10,10), 'transparent') fontsize = self.returnFontSize(canvasHeight) im.fontPointsize(fontsize) tm = TypeMetric() im.fontTypeMetrics(node['name'], tm) if tm.textWidth() > canvasWidth: canvasWidth = int(tm.textWidth()) + 5 im = Image(Geometry(canvasWidth,canvasHeight), 'transparent') im.density("72x72") im.magick('RGB') im.resolutionUnits(ResolutionType.PixelsPerInchResolution) im.strokeAntiAlias(True) color = (node['rgb'][0],node['rgb'][1],node['rgb'][2]) color = self.rgb_to_hex( color ) im.fillColor(color); im.strokeWidth(2); if circleWidth <= 20: im.strokeColor("transparent"); else: im.strokeColor("black"); if circleWidth <= 50: im.strokeWidth(1); circle = DrawableCircle( canvasWidth/2 , canvasHeight/2, (canvasWidth/2) + (circleWidth/2), (canvasHeight/2) + (circleHeight/2)) im.draw(circle) im.fillColor("white"); im.strokeColor("black"); im.strokeWidth(1); fontsize = self.returnFontSize(canvasHeight) im.fontPointsize(fontsize) tm = TypeMetric() im.fontTypeMetrics(node['name'], tm) textWidth = tm.textWidth() textHeight = tm.textHeight() if fontsize <= 30: im.strokeColor("transparent") text = DrawableText((canvasWidth / 2) - (textWidth/2), canvasHeight/2 + 6 , node['name']) im.draw(text) im.write(self.dataCircles + str(node['id']) + '.png')
from pgmagick import Image, Geometry, Color, TypeMetric, \ DrawableText, DrawableList, DrawableGravity, GravityType im = Image(Geometry(600, 600), Color("transparent")) im.fontPointsize(30) im.fillColor(Color("#f010f0")) im.strokeColor(Color("transparent")) im.font("Vera.ttf") dl = DrawableList() dl.append(DrawableGravity(GravityType.CenterGravity)) dl.append(DrawableText(0, 0, "center")) tm = TypeMetric() im.fontTypeMetrics("northn", tm) font_height = tm.textHeight() dl.append(DrawableGravity(GravityType.NorthGravity)) dl.append(DrawableText(0, font_height / 2., "north")) dl.append(DrawableGravity(GravityType.WestGravity)) dl.append(DrawableText(0, 0, "west")) dl.append(DrawableGravity(GravityType.EastGravity)) dl.append(DrawableText(0, 0, "east")) dl.append(DrawableText(0, 20, "east-long")) dl.append(DrawableGravity(GravityType.SouthGravity)) dl.append(DrawableText(0, 0, "south")) dl.append(DrawableGravity(GravityType.NorthWestGravity))