aboutsummaryrefslogtreecommitdiff
path: root/wqflask/utility/pillow_utils.py
diff options
context:
space:
mode:
authorzsloan2020-08-17 17:14:29 -0500
committerGitHub2020-08-17 17:14:29 -0500
commit75ebbf446606d7498bb16a01a4912c66eba17cb5 (patch)
tree0bca7be443ff8b897e3b84075d5c756a4d4fd66b /wqflask/utility/pillow_utils.py
parent1e421a063d750df485a768aa6da14b3db592d409 (diff)
parentd157019159ae3eb2e3efb02d874a1b4edfc559cb (diff)
downloadgenenetwork2-75ebbf446606d7498bb16a01a4912c66eba17cb5.tar.gz
Merge pull request #417 from BonfaceKilz/feature/pil-pillow-conversion
Resolve merge conflicts from Pil Pillow conversion branch
Diffstat (limited to 'wqflask/utility/pillow_utils.py')
-rw-r--r--wqflask/utility/pillow_utils.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/wqflask/utility/pillow_utils.py b/wqflask/utility/pillow_utils.py
new file mode 100644
index 00000000..dfbf3e19
--- /dev/null
+++ b/wqflask/utility/pillow_utils.py
@@ -0,0 +1,25 @@
+from PIL import Image, ImageColor, ImageDraw, ImageFont
+
+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("/tmp/{}.png".format(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)