How to use the yoga.image.helpers.image_have_alpha function in yoga

To help you get started, we’ve selected a few yoga examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wanadev / yoga / test / test_image_helpers.py View on Github external
def test_alpha_threshold(self, image_path, threshold, is_alpha):
        image = Image.open("test/images/threshold.png")
        if is_alpha:
            assert helpers.image_have_alpha(image, threshold)
        else:
            assert not helpers.image_have_alpha(image, threshold)
github wanadev / yoga / test / test_image_helpers.py View on Github external
def test_alpha_threshold(self, image_path, threshold, is_alpha):
        image = Image.open("test/images/threshold.png")
        if is_alpha:
            assert helpers.image_have_alpha(image, threshold)
        else:
            assert not helpers.image_have_alpha(image, threshold)
github wanadev / yoga / yoga / image / __init__.py View on Github external
if not hasattr(output_file, "write"):
        output_file = open(output_file, "ab")

    # resize
    if options["resize"] != "orig":
        image.thumbnail(options["resize"], Image.LANCZOS)

    # output format
    output_format = None

    if options["output_format"] == "orig":
        output_format = image.format.lower()
    elif options["output_format"] in ("jpeg", "png"):
        output_format = options["output_format"]
    else:  # auto
        if image_have_alpha(image, options["opacity_threshold"]):
            output_format = "png"
        else:
            # XXX Maybe we should try to encode in both format
            # and choose the smaller output?
            output_format = "jpeg"

    # convert / optimize
    output_image_bytes = None
    if output_format == "jpeg":
        output_image_bytes = pyguetzli.process_pil_image(
                image, int(options["jpeg_quality"] * 100))
    else:
        pass
        image_io = io.BytesIO()
        image.save(image_io, format="PNG", optimize=False)
        image_io.seek(0)