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 1 commit
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
Prev Previous commit
Next Next commit
Add python3 support to stdin in papirus-draw
schwma committed Mar 11, 2018
commit fe3e3b17387b8effd00769da604b503d2b7660d0
23 changes: 15 additions & 8 deletions bin/papirus-draw
Original file line number Diff line number Diff line change
@@ -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()