import hashlib
import base64


def hashed(source_filename, prepared_options, thumbnail_extension, **kwargs):
    """
    Generate a short hashed thumbnail filename.

    Creates a 12 character url-safe base64 sha1 filename (plus the extension),
    for example: ``6qW1buHgLaZ9.jpg``.
    """
    parts = ':'.join([source_filename] + prepared_options)
    short_sha = hashlib.sha1(parts.encode('utf-8')).digest()
    short_hash = base64.urlsafe_b64encode(short_sha[:9]).decode('utf-8')
    return '.'.join([short_hash, thumbnail_extension])