def METHOD_NAME(epubfile, fpath_out, crop=None):
    """
    Generate a thumbnail image from `epubfile` and save it to `fpath_out`.
    Raises ThumbnailGenerationError if thumbnail extraction fails.
    """
    try:
        book = ebooklib.epub.read_epub(epubfile)
        # 1. try to get cover image from book metadata (content.opf)
        cover_item = None
        covers = book.get_metadata("http://www.idpf.org/2007/opf", "cover")
        if covers:
            cover_tuple = covers[0]  # ~= (None, {'name':'cover', 'content':'item1'})
            cover_item_id = cover_tuple[1]["content"]
            for item in book.items:
                if item.id == cover_item_id:
                    cover_item = item
        if cover_item:
            image_data = BytesIO(cover_item.get_content())
        else:
            # 2. fallback to get first image in the ePub file
            images = list(book.get_items_of_type(ebooklib.ITEM_IMAGE))
            if not images:
                raise ThumbnailGenerationError(
                    "ePub file {} contains no images.".format(epubfile)
                )
            # TODO: get largest image of the bunch
            image_data = BytesIO(images[0].get_content())
        # Save image_data to fpath_out
        im = Image.open(image_data)
        im = scale_and_crop_thumbnail(im, crop=crop)
        im.save(fpath_out)
    except Exception as e:
        raise ThumbnailGenerationError("Fail on ePub {} {}".format(epubfile, e))