#!/usr/bin/env python3
"""Blur one rectangle of a lesson screenshot in place: redact.py <jpg> x y w h"""
import sys
from PIL import Image, ImageFilter
p, x, y, w, h = sys.argv[1], *map(int, sys.argv[2:6])
im = Image.open(p).convert('RGB')
box = (max(0, x), max(0, y), min(im.width, x + w), min(im.height, y + h))
if box[2] > box[0] and box[3] > box[1]:
    region = im.crop(box).filter(ImageFilter.GaussianBlur(9))
    im.paste(region, box)
    im.save(p, quality=82)
