diff --git a/bin/papirus-draw b/bin/papirus-draw index c8b945c..cc9e428 100755 --- a/bin/papirus-draw +++ b/bin/papirus-draw @@ -8,6 +8,7 @@ import time from papirus import Papirus from PIL import Image import argparse +from io import BytesIO # Command line usage # papirus-draw "filepath" -t "crop|resize" @@ -44,8 +45,15 @@ def draw_image(papirus, filepath, type): # padding for placing the image xpadding = 0 ypadding = 0 + # check whether to load the image from stdin or fs + if (filepath == "-"): + # load the image from stdin + image = BytesIO(read_stdin()) + else: + # load the image from fs + image = filepath # open the image to display - file = Image.open(filepath) + file = Image.open(image) # display with crop option if type == "crop": # Landscape image @@ -77,5 +85,13 @@ def draw_image(papirus, filepath, type): papirus.update() print(message) +def read_stdin(): + # Handle stdin differences between python2 and python3 + if sys.version_info >= (3, 0): + stdin = sys.stdin.buffer + else: + stdin = sys.stdin + return stdin.read() + if __name__ == '__main__': main()