Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to pipe images into stdin in papirus-draw #180

Merged
merged 3 commits into from
Mar 12, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion bin/papirus-draw
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()