Files
gnome-jarvis/computer-use/py/normalize_frame.py
T
2026-09-11 14:20:57 -04:00

15 lines
614 B
Python

#!/usr/bin/env python3
import sys
from PIL import Image
source, target, cap, quality = sys.argv[1], sys.argv[2], int(sys.argv[3]), int(sys.argv[4])
with Image.open(source) as image:
image = image.convert('RGB')
if len(sys.argv) == 9:
x, y, width, height = [int(v) for v in sys.argv[5:9]]
image = image.crop((x, y, x + width, y + height))
scale = min(1.0, cap / max(image.width, image.height))
if scale < 1.0:
image = image.resize((round(image.width * scale), round(image.height * scale)), Image.Resampling.LANCZOS)
image.save(target, 'WEBP', quality=quality, method=4)