'Create thumbnail of cover or return previously cached thumb.
Test thumb archive for currently cached cover. Return cached version, or create
and cache new version.
Args:
title (dict): book metadata
image_dir (str): directory to write thumb data to
thumb_file (str): filename to save thumb as
Output:
(file): thumb written to /images
(archive): current thumb archived under cover crc'

def generate_thumbnail(self, title, image_dir, thumb_file):

    def _open_archive(mode='r'):
        try:
            return ZipFile(self.thumbs_path, mode=mode, allowZip64=True)
        except:
            pass
    with lopen(title['cover'], 'rb') as f:
        data = f.read()
    cover_crc = hex(zlib.crc32(data))
    uuid = title.get('uuid')
    if uuid:
        zf = _open_archive()
        if (zf is not None):
            with zf:
                try:
                    zf.getinfo((uuid + cover_crc))
                except:
                    pass
                else:
                    thumb_data = zf.read((uuid + cover_crc))
                    with open(os.path.join(image_dir, thumb_file), 'wb') as f:
                        f.write(thumb_data)
                    return
        thumb_data = scale_image(data, width=self.thumb_width, height=self.thumb_height)[(-1)]
        with lopen(os.path.join(image_dir, thumb_file), 'wb') as f:
            f.write(thumb_data)
        if (zf is not None):
            zf = _open_archive('a')
            if (zf is not None):
                with zf:
                    zf.writestr((uuid + cover_crc), thumb_data)
