How to use the yoga.image 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.py View on Github external
def test_input_file(self, input_):
        output = io.BytesIO()
        yoga.image.optimize(input_, output)
        output.seek(0)
        assert output.read().startswith(_MAGIC_PNG)
github wanadev / yoga / test / test_image.py View on Github external
def test_jpeg_quality(self):
        output1 = io.BytesIO()
        yoga.image.optimize("test/images/image1.jpg", output1, {
            "jpeg_quality": 1.00
            })
        output1.seek(0)

        output2 = io.BytesIO()
        yoga.image.optimize("test/images/image1.jpg", output2, {
            "jpeg_quality": 0.50
            })
        output2.seek(0)

        assert len(output2.read()) < len(output1.read())
github wanadev / yoga / yoga / model / helpers.py View on Github external
if valid_image_path is None:
            image_io = fallback_texture
        elif textures is not None:
            image_io = textures[valid_image_path]
        else:
            image_io = io.BytesIO(open(valid_image_path, "rb").read())

        # Optimizing the texture if requested
        if optimize_textures:
            if not quiet:
                if valid_image_path is not None:
                    print("Optimizing texture %s..." % valid_image_path)
                else:
                    print("Optimizing fallback texture...")
            output_io = io.BytesIO()
            yoga.image.optimize(image_io, output_io, image_options)
            image_io = output_io

        image_io.seek(0)
        image_bytes = image_io.read()

        # Convert to cffi
        image_bytes_c = ffi.new("char[%d]" % len(image_bytes), image_bytes)
        image.bytes_length = len(image_bytes)
        image.bytes = image_bytes_c
        image.id = len(optimized_textures)

        optimized_textures[valid_image_path] = image
        image = image.next

        # @note Save the bytes to a dictionnary so that the garbage collector
        # does not occur before exporting the scene a bit later