# -*- coding: utf-8 -*-
# imagecodecs/__main__.py

"""Command line script for the imagecodecs package."""

import sys

from matplotlib.pyplot import show

from tifffile import imshow

import imagecodecs


def main(argv=None, verbose=True, decoders=None):
    """Imagecodecs command line usage main function."""
    if argv is None:
        argv = sys.argv

    if len(argv) != 2:
        print('Usage: imagecodecs filename')
        return -1

    fname = argv[1]

    with open(fname, 'rb') as fh:
        data = fh.read()

    if decoders is None:
        decoders = [
            imagecodecs.png_decode,
            imagecodecs.jpeg8_decode,
            imagecodecs.jpeg12_decode,
            imagecodecs.jpegsof3_decode,
            imagecodecs.jpegls_decode,
            imagecodecs.j2k_decode,
            imagecodecs.jxr_decode,
            imagecodecs.webp_decode,
        ]

    image = None
    for decode in decoders:
        if verbose:
            print()
            print(decode.__name__)
        try:
            image = decode(data)
            if image.dtype == 'object':
                image = None
                raise ValueError('failed')
        except Exception as exception:
            # raise(exception)
            if verbose:
                print(' ', exception)
            continue
        break

    if image is None:
        if verbose:
            print()
            print('Could not decode the file')
        return -1
    if verbose:
        print(' ', image.shape, image.dtype)

    imshow(image, title=fname)
    show()
    return 0


sys.exit(main())

@@ -206,177 +206,771 @@
 def 
-main(argv=None, verbose=True, decoders=None):%0A    %22%22%22Imagecodecs command line usage main function.%22%22%22%0A    if argv is None:%0A        argv = sys.argv%0A%0A    if len(argv) != 2
+askopenfilename(**kwargs):%0A    %22%22%22Return file name(s) from Tkinter's file open dialog.%22%22%22%0A    try:%0A        from Tkinter import Tk%0A        import tkFileDialog as filedialog%0A    except ImportError:%0A        from tkinter import Tk, filedialog%0A    root = Tk()%0A    root.withdraw()%0A    root.update()%0A    filenames = filedialog.askopenfilename(**kwargs)%0A    root.destroy()%0A    return filenames%0A%0A%0Adef main(argv=None, verbose=True, decoders=None):%0A    %22%22%22Imagecodecs command line usage main function.%22%22%22%0A    if argv is None:%0A        argv = sys.argv%0A%0A    if len(argv) %3C 2:%0A        fname = askopenfilename(title='Select a. image file')%0A        if not fname:%0A            print('No file selected')%0A            return -1%0A    elif len(argv) == 2:%0A        fname = argv%5B1%5D%0A    else
 :%0A  
@@ -1035,29 +1035,8 @@
 -1%0A%0A
-    fname = argv%5B1%5D%0A%0A
     
@@ -1450,16 +1450,34 @@
      %5D%0A%0A
+    messages = %5B%5D%0A
     imag
@@ -1517,83 +1517,8 @@
 rs:%0A
-        if verbose:%0A            print()%0A            print(decode.__name__)%0A
     
@@ -1757,45 +1757,59 @@
     
-if verbose:%0A                print(' '
+messages.append('%25s: %25s' %25 (decode.__name__.upper()
 , ex
@@ -1808,32 +1808,33 @@
 er(), exception)
+)
 %0A            con
@@ -1865,63 +1865,158 @@
  if 
-image is None:%0A        if verbose:%0A            print()%0A
+verbose:%0A        print()%0A    if image is None:%0A        print('Could not decode the file%5Cn')%0A        if verbose:%0A            for message in messages:%0A 
     
@@ -2027,41 +2027,24 @@
     
+   
 print(
-'Could not decode the file'
+message
 )%0A  
@@ -2093,12 +2093,76 @@
 int(
-' ',
+%22%25s: %25s %25s%22 %25 (decode.__name__.upper(),%0A                            
  ima
@@ -2183,16 +2183,17 @@
 e.dtype)
+)
 %0A%0A    im

Update imagecodecs/__main__.py