diff --git a/brother_ql/cli.py b/brother_ql/cli.py index 17bc584..f08ce12 100755 --- a/brother_ql/cli.py +++ b/brother_ql/cli.py @@ -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.') diff --git a/brother_ql/conversion.py b/brother_ql/conversion.py index 2340f25..3d702c9 100755 --- a/brother_ql/conversion.py +++ b/brother_ql/conversion.py @@ -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