From af81ac549ca5205e1b8dc70ee4e4febbe39d6d71 Mon Sep 17 00:00:00 2001 From: schwma <37244550+schwma@users.noreply.github.com> Date: Sun, 11 Mar 2018 15:12:30 +0100 Subject: [PATCH 1/3] Add ability to pipe images into stdin in papirus-draw --- bin/papirus-draw | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/bin/papirus-draw b/bin/papirus-draw index c8b945c..9df2d60 100755 --- a/bin/papirus-draw +++ b/bin/papirus-draw @@ -7,6 +7,7 @@ import sys import time from papirus import Papirus from PIL import Image +import StringIO import argparse # Command line usage @@ -44,8 +45,16 @@ def draw_image(papirus, filepath, type): # padding for placing the image xpadding = 0 ypadding = 0 - # open the image to display - file = Image.open(filepath) + # check whether to load the image from stdin or fs + if (filepath == "-"): + # load the image to display from stdin + image_stdin = "" + for line in sys.stdin: + image_stdin += line + file = Image.open(StringIO.StringIO(image_stdin)) + else: + # open the image to display + file = Image.open(filepath) # display with crop option if type == "crop": # Landscape image From fe3e3b17387b8effd00769da604b503d2b7660d0 Mon Sep 17 00:00:00 2001 From: schwma <37244550+schwma@users.noreply.github.com> Date: Sun, 11 Mar 2018 17:11:06 +0100 Subject: [PATCH 2/3] Add python3 support to stdin in papirus-draw --- bin/papirus-draw | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/bin/papirus-draw b/bin/papirus-draw index 9df2d60..f428d44 100755 --- a/bin/papirus-draw +++ b/bin/papirus-draw @@ -7,8 +7,8 @@ import sys import time from papirus import Papirus from PIL import Image -import StringIO import argparse +from io import BytesIO # Command line usage # papirus-draw "filepath" -t "crop|resize" @@ -47,14 +47,13 @@ def draw_image(papirus, filepath, type): ypadding = 0 # check whether to load the image from stdin or fs if (filepath == "-"): - # load the image to display from stdin - image_stdin = "" - for line in sys.stdin: - image_stdin += line - file = Image.open(StringIO.StringIO(image_stdin)) + # load the image from stdin + image = BytesIO(read_stdin()) else: - # open the image to display - file = Image.open(filepath) + # load the image from fs + image = filepath + # open the image to display + file = Image.open(image) # display with crop option if type == "crop": # Landscape image @@ -86,5 +85,13 @@ def draw_image(papirus, filepath, type): papirus.update() print(message) +def read_stdin(): + # Handle stdin differences between + if sys.version_info >= (3, 0): + stdin = sys.stdin.buffer + else: + stdin = sys.stdin + return stdin.read() + if __name__ == '__main__': main() From 3f39e8e000e061a17019954decbe34520a5b1229 Mon Sep 17 00:00:00 2001 From: schwma <37244550+schwma@users.noreply.github.com> Date: Sun, 11 Mar 2018 17:17:40 +0100 Subject: [PATCH 3/3] Fix incomplete comment --- bin/papirus-draw | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/papirus-draw b/bin/papirus-draw index f428d44..cc9e428 100755 --- a/bin/papirus-draw +++ b/bin/papirus-draw @@ -86,7 +86,7 @@ def draw_image(papirus, filepath, type): print(message) def read_stdin(): - # Handle stdin differences between + # Handle stdin differences between python2 and python3 if sys.version_info >= (3, 0): stdin = sys.stdin.buffer else: