INNER CODE UNIT · Python

crop

TheAssemblyArmada/Vanilla-Conquer · scripts/tgautil.py:37

def crop(tga_file):
    with Image.open(tga_file) as image:
        image = image.convert('RGBA')
        alpha = image.split()[-1]
        left, top, right, bottom = 0, 0, image.width, image.height
        found_left, found_top, found_right, found_bottom = False, False, False, False
        for y in range(0, image.height):
            if found_top and found_bottom:
                break
            for x in range(0, image.width):
                if found_top and found_bottom:
                    break
                if not found_top and alpha.getpixel((x, y)) != 0:
                    top = y
                    found_top = True
                if not found_bottom and alpha.getpixel((x, image.height - y - 1)) != 0:
                    bottom = image.height - y
                    found_bottom = True

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…