aboutsummaryrefslogtreecommitdiff
path: root/wqflask/utility/pillow_utils.py
diff options
context:
space:
mode:
authorArthur Centeno2021-10-25 21:04:23 +0000
committerArthur Centeno2021-10-25 21:04:23 +0000
commit499a80f138030c4de1629c043c8f9401a99894ea (patch)
tree449dcae965d13f966fb6d52625fbc86661c8c6a0 /wqflask/utility/pillow_utils.py
parent6151faa9ea67af4bf4ea95fb681a9dc4319474b6 (diff)
parent700802303e5e8221a9d591ba985d6607aa61e1ce (diff)
downloadgenenetwork2-499a80f138030c4de1629c043c8f9401a99894ea.tar.gz
Merge github.com:genenetwork/genenetwork2 into acenteno
Diffstat (limited to 'wqflask/utility/pillow_utils.py')
-rw-r--r--wqflask/utility/pillow_utils.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/wqflask/utility/pillow_utils.py b/wqflask/utility/pillow_utils.py
new file mode 100644
index 00000000..5713e155
--- /dev/null
+++ b/wqflask/utility/pillow_utils.py
@@ -0,0 +1,31 @@
+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)