diff options
author | Arthur Centeno | 2021-04-09 20:38:21 +0000 |
---|---|---|
committer | Arthur Centeno | 2021-04-09 20:38:21 +0000 |
commit | e2b04a322f26670782fe7f7c39bcebc508fdabdd (patch) | |
tree | a51c32bae4d544cc0beea19f455ccc52f0544a4c /wqflask/utility/pillow_utils.py | |
parent | 187cd40bd3273b50d2813bfccf98bfadbb8c14ff (diff) | |
parent | ef51e08753defdfc7f3e67f8788cd1362d2cf631 (diff) | |
download | genenetwork2-e2b04a322f26670782fe7f7c39bcebc508fdabdd.tar.gz |
Merge branch 'testing' of github.com:genenetwork/genenetwork2 into acenteno
Diffstat (limited to 'wqflask/utility/pillow_utils.py')
-rw-r--r-- | wqflask/utility/pillow_utils.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/wqflask/utility/pillow_utils.py b/wqflask/utility/pillow_utils.py new file mode 100644 index 00000000..c486abba --- /dev/null +++ b/wqflask/utility/pillow_utils.py @@ -0,0 +1,27 @@ +from PIL import Image, ImageColor, ImageDraw, ImageFont + +from utility.tools import TEMPDIR + +import utility.logger +logger = utility.logger.getLogger(__name__ ) + +BLACK = ImageColor.getrgb("black") +WHITE = ImageColor.getrgb("white") + +# def draw_rotated_text(canvas: Image, text: str, font: ImageFont, xy: tuple, fill: ImageColor=BLACK, angle: int=-90): +def draw_rotated_text(canvas, text, font, xy, fill=BLACK, angle=-90): + # type: (Image, str, ImageFont, tuple, ImageColor, int) + """Utility function draw rotated text""" + tmp_img = Image.new("RGBA", font.getsize(text), color=(0, 0, 0, 0)) + draw_text = ImageDraw.Draw(tmp_img) + draw_text.text(text=text, xy=(0, 0), font=font, fill=fill) + tmp_img2 = tmp_img.rotate(angle, expand=1) + tmp_img2.save("/{0}/{1}.png".format(TEMPDIR, text), format="png") + canvas.paste(im=tmp_img2, box=tuple([int(i) for i in xy])) + +# def draw_open_polygon(canvas: Image, xy: tuple, fill: ImageColor=WHITE, outline: ImageColor=BLACK): +def draw_open_polygon(canvas, xy, fill=None, outline=BLACK, width=0): + # type: (Image, tuple, ImageColor, ImageColor) + draw_ctx = ImageDraw.Draw(canvas) + draw_ctx.polygon(xy, fill=fill) + draw_ctx.line(xy, fill=outline, width=width) |