def METHOD_NAME(image, service, layers, **kw):
    img = image.as_image()
    if hasattr(image.image_opts, "transparent") and image.image_opts.transparent:
        img = img.convert("LA").convert("RGBA")
    else:
        img = img.convert("L").convert("RGB")
    return ImageSource(img, image.image_opts)