def to_png(self): size = tuple([self.pt_to_px(p) for p in self.size]) thickness = self.pt_to_px(self.thickness) image = Image.new('RGBA', size) draw = ImageDraw.Draw(image) fill = helpers.standarize_colors(self.fill) width, height = size half_height = int(height / 2) # outline draw.pieslice((0, 0, height - 1, height - 1), 90, 270, fill=self.outline, outline=self.outline) draw.pieslice((width - height, 0, width - 1, height - 1), 270, 90, fill=self.outline, outline=self.outline) draw.rectangle((half_height, 0, width - half_height - 1, height - 1), fill=self.outline, outline=self.outline) #fill draw.pieslice((0 + thickness, 0 + thickness, height - thickness - 1, height - thickness - 1), 90, 270, fill=fill, outline=fill) draw.pieslice((width - height + thickness, 0 + thickness, width - thickness - 1, height - thickness - 1), 270, 90, fill=fill, outline=fill) draw.rectangle((half_height, 0 + thickness, width - half_height - 1, height - thickness - 1), fill=fill, outline=fill) return ImageWrapper(image, *self.size)
def to_png(self): size = map(self.pt_to_px, self.size) image = Image.new('RGBA', size) draw = ImageDraw.Draw(image) fill = helpers.standarize_colors(self.fill) width, height = size thickness = self.pt_to_px(self.thickness) draw.rectangle((0, 0, width - 1, height - 1), fill=self.outline, outline=self.outline) draw.rectangle((0 + thickness, 0 + thickness, width - 1 - thickness, height - 1 - thickness), fill=fill, outline=fill) return ImageWrapper(image, *self.size)
def to_png(self): padding = self.pt_to_px(self.padding) font = self._get_font(self.font_type, self.font_size, self.font_typeface) # try to get font size to check if fonts support all characters in text try: text_size = font.getsize(self.text) except UnicodeEncodeError: self.text = helpers.normalize_str(self.text) text_size = font.getsize(self.text) image_size = [x + 2 * padding for x in text_size] background = helpers.standarize_colors(self.background) image = Image.new('RGBA', image_size, background) draw = ImageDraw.Draw(image) draw.text((padding,) * 2, self.text, font=font, fill=self.font_color) return ImageWrapper(image, *map(self.px_to_pt, image_size))