import json


def image_description_dict(description):
    """Return dictionary from image description byte string.

    Raise ValuError if description is of unknown format.

    >>> image_description_dict(b'shape=(256, 256, 3)')
    {'shape': (256, 256, 3)}
    >>> description = b'{"shape": [256, 256, 3], "axes": "YXS"}'
    >>> image_description_dict(description)  # doctest: +SKIP
    {'shape': [256, 256, 3], 'axes': 'YXS'}

    """
    if description.startswith(b'shape='):
        # old style 'shaped' description
        shape = tuple(int(i) for i in description[7:-1].split(b','))
        return dict(shape=shape)
    if description.startswith(b'{') and description.endswith(b'}'):
        # JSON description
        return json.loads(description.decode('utf-8'))
    raise ValueError("unknown image description")