def maybe_download_emnist(data_dir, quiet=0, shape=None):
    """
    Download emnist data if it hasn't already been downloaded. Do some
    post-processing to put it in a more useful format. End result is a directory
    called `emnist-byclass` which contains a separate pklz file for each emnist
    class.

    Pixel values of stored images are uint8 values up to 255.
    Images for each class are put into a numpy array with shape (n_images_in_class, 28, 28).
    This numpy array is pickled and stored in a zip file with name <class char>.pklz.

    Parameters
    ----------
    data_dir: str
         Directory where files should be stored.

    """
    emnist_dir = os.path.join(data_dir, 'emnist')

    if _validate_emnist(emnist_dir):
        print("EMNIST data seems to be present already.")
    else:
        print("EMNIST data not found, downloading and processing...")
        try:
            shutil.rmtree(emnist_dir)
        except FileNotFoundError:
            pass

        raw_dir = _download_emnist(data_dir)

        with cd(raw_dir):
            images, labels = _emnist_load_helper(emnist_gz_names[0], emnist_gz_names[1])
            images1, labels1 = _emnist_load_helper(emnist_gz_names[2], emnist_gz_names[3])

        with cd(data_dir):
            os.makedirs('emnist', exist_ok=False)

            print("Processing...")
            with cd('emnist'):
                x = np.concatenate((images, images1), 0)
                y = np.concatenate((labels, labels1), 0)

                # Give images the right orientation so that plt.imshow(x[0]) just works.
                x = np.moveaxis(x.reshape(-1, 28, 28), 1, 2)

                for i in sorted(set(y.flatten())):
                    keep = y == i
                    x_i = x[keep.flatten(), :]
                    if i >= 36:
                        char = chr(i-36+ord('a'))
                    elif i >= 10:
                        char = chr(i-10+ord('A'))
                    else:
                        char = str(i)

                    if quiet >= 2:
                        pass
                    elif quiet == 1:
                        print(char)
                    elif quiet <= 0:
                        print(char)
                        print(image_to_string(x_i[0, ...]))

                    file_i = char + '.pklz'
                    with gzip.open(file_i, 'wb') as f:
                        dill.dump(x_i, f, protocol=dill.HIGHEST_PROTOCOL)

    if shape is not None:
        maybe_convert_emnist_shape(data_dir, shape)