Skip to content

Commit

Permalink
CLI brother_ql print: use click.File() to allow input from stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
pklaus committed Sep 6, 2018
1 parent ec4b7a9 commit 0c59fa9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion brother_ql/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def env(ctx, *args, **kwargs):
print("\n##################\n")

@cli.command('print', short_help='Print a label')
@click.argument('images', nargs=-1, metavar='IMAGE [IMAGE] ...')
@click.argument('images', nargs=-1, type=click.File('rb'), metavar='IMAGE [IMAGE] ...')
@click.option('-l', '--label', type=click.Choice(label_sizes), envvar='BROTHER_QL_LABEL', help='The label (size, type - die-cut or endless). Run `brother_ql info labels` for a full list including ideal pixel dimensions.')
@click.option('-r', '--rotate', type=click.Choice(('auto', '0', '90', '180', '270')), default='auto', help='Rotate the image (counterclock-wise) by this amount of degrees.')
@click.option('-t', '--threshold', type=float, default=70.0, help='The threshold value (in percent) to discriminate between black and white pixels.')
Expand Down
7 changes: 4 additions & 3 deletions brother_ql/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,11 @@ def convert(qlr, images, label, **kwargs):
for image in images:
if isinstance(image, Image.Image):
im = image
elif isinstance(image, str):
im = Image.open(image)
else:
raise NotImplementedError("The image argument needs to be an Image() instance or the filename to an image.")
try:
im = Image.open(image)
except:
raise NotImplementedError("The image argument needs to be an Image() instance, the filename to an image, or a file handle.")

if im.mode.endswith('A'):
# place in front of white background and get red of transparency
Expand Down

0 comments on commit 0c59fa9

Please sign in to comment.