def reset_canvas(self): image = Image.fromarray(self.pixel_array, mode=self.camera.image_mode) self.canvas = aggdraw.Draw(image)
def get_image( self, loader: ImageLoader, width: int, height: int, bordered_sides: int = imageutils.ALL_SIDES, triangled = True, ) -> Image.Image: pictured_printings = self.sorted_imageds images = [ image.resize( ( width, image.height * width // image.width, ), Image.LANCZOS, ) if isinstance(image, Image.Image) and image.width != width else image for image in Promise.all( tuple( loader.get_image(option, crop = True) if isinstance(option, Printing) else Promise.resolve(option) for option in pictured_printings ) ).get() ] background = Image.new('RGBA', (width, height), (0, 0, 0, 255)) draw = ImageDraw.Draw(background) cx, cy, content_width, content_height = imageutils.shrunk_box( x = 0, y = 0, w = width, h = height, shrink = self._BORDER_WIDTH - 1, sides = bordered_sides, ) font_size = 27 + int(27 * min(width, self._FULL_WIDTH) / self._FULL_WIDTH) for span, option, image, in zip( imageutils.section(content_height, len(pictured_printings)), pictured_printings, images, ): start, stop = span if isinstance(option, Printing): background.paste( imageutils.fit_image(image, content_width, stop - start + 1), (cx, start + cy), ) imageutils.draw_name( draw = draw, name = self._name_printing(option), box = ( cx, start + cy, content_width, stop - start, ), font_path = self._FONT_PATH, font_size = font_size, ) else: background.paste( option.get_image( loader = loader, width = content_width, height = stop - start, bordered_sides = imageutils.LEFT_SIDE, triangled = True, ), (cx, start + cy), ) agg_draw = aggdraw.Draw(background) if triangled: imageutils.triangled_inlined_box( draw = agg_draw, box = (0, 0, width, height), color = self._BORDER_COLOR, bar_color = self._BORDER_TRIANGLE_COLOR, width = self._BORDER_WIDTH, triangle_length = self._BORDER_WIDTH, sides = bordered_sides, ) else: imageutils.inline_box( draw = agg_draw, box = (0, 0, width, height), color = self._BORDER_COLOR, width = self._BORDER_WIDTH, sides = bordered_sides, ) return background
# polyline0 = Rectangle(ORIGIN, width = W/4, height = H/8) # polyline0 = Polyline(points = points_to_tuple(ORIGIN, CENTER)) polyline0.record_name() polyline0.set_pen_color(LIMEGREEN) polyline0.set_brush_color(LIMEGREEN) polyline0.add_decoration({'type': 'tick', 'position': 'tip'}) polyline0.add_decoration({'type': 'arrow', 'position': 'foot'}) # #sketch.add_graphics(rect0, polyline0) #sketch.refresh() # img = Image.new('RGBA', (W, H), DEFAULT_BACKGROUND_COLOR) canvas = aggdraw.Draw(img) # This draws on the canvas directly, without creating an object pen = aggdraw.Pen((255, 0, 255), DEFAULT_PEN_WIDTH) aggdrawstring = 'M600,200 L400,600' symbol = aggdraw.Symbol(aggdrawstring) canvas.symbol((0, 0), symbol, pen) # Draw the objects created earlier via their method polyline0.draw(canvas) rect0.draw(canvas) canvas.flush() img.save('alinesegment.png') os.system(' '.join(['open -a preview alinesegment.png']))
def _get_canvas(self, image): """Returns AGG image object """ import aggdraw return aggdraw.Draw(image)
def configure_surface(self, width, height): # create agg surface the size of the window self.surface = agg.Draw("RGBA", (width, height), 'black') # inform the base class about the actual window size self.configure(width, height)
def _get_canvas(self, image): """Return AGG image object.""" return aggdraw.Draw(image)
iTopright[1] + random.randrange(-hh, hh + 1)) iBotleft = (100, 600) aBotleft = (iBotleft[0] + random.randrange(-hh, hh + 1), iBotleft[1] + random.randrange(-hh, hh + 1)) iBotright = (600, 600) aBotright = (iBotright[0] + random.randrange(-hh, hh + 1), iBotright[1] + random.randrange(-hh, hh + 1)) slingers.append(Slinger(howbig, iTopleft, iTopright, aTopleft, aTopright)) slingers.append(Slinger(howbig, iBotleft, iBotright, aBotleft, aBotright)) slingers.append(Slinger(howbig, iTopleft, iBotleft, aTopleft, aBotleft)) slingers.append(Slinger(howbig, iTopright, iBotright, aTopright, aBotright)) hiliteimg = Image.new("RGBA", imgsize, (255, 255, 255, 0)) slingerimg = Image.new("L", imgsize, 0) canvas = aggdraw.Draw(slingerimg) bulbsimg = Image.new("RGBA", imgsize, (0, 0, 0, 0)) for slinger in slingers: slinger.draw_core(canvas) for light in slinger.lights: color = tuple( round(255 * i) for i in colorsys.hsv_to_rgb(random.random(), 1.0, 1.0)) #color = 'gold' if light.beat == 0 or light.beat == 1 else 'silver' light.draw_highlight(hiliteimg, color) light.draw_bulb_u(bulbsimg) light.draw_bulb_l(bulbsimg, color) canvas.flush()