import uuid


def extract_images(image, spriteWidth_x, spriteWidth_y):
    """
    Convert sprite-sheet to individual sprites.

    Each sprite is generated by indexing through the image by sprite size.
    Images are named as a hexadecimal UUID.
    """

    imgShape = image.shape;
    images = {}

    for y in range(0,imgShape[1],spriteWidth_y):
        for x in range(0,imgShape[0],spriteWidth_x):
            try:
                subImage = image[y:y+spriteWidth_y,x:x+spriteWidth_x,:]

                name = str(uuid.uuid4().hex) + '.png'

                images[name] = {}
                images[name]['img'] = subImage

            except Exception as e:
                print(e)
    return images