Using PIL in Python, I am superimposing a PNG image on top of another, larger image. The smaller image is semi-transparent.
I would like for the area behind the smaller image to be blurred on the larger image. The following code blurs a rectangular area:
box = (3270, 1150, 4030, 2250) # (x1, y1, x2, y2)
ic = outputImage.crop(box)
ic = ic.filter(ImageFilter.BoxBlur(20))
outputImage.paste(ic, box)
However, I need to blur a rectangular area that has rounded corners.
This is what the superimposed image looks like:
So, is it possible to define a custom shape for a cropped area in PIL?
If not, is it possible to at least crop circle-shaped areas? (For full coverage and without any overhang, my area would have to broken down into 6 sub-areas: 4 circles and 2 rectangles. Doing all this will slow down my code, but I will take whatever solution I can get.)
I understand that this can be done with Numpy, but I would prefer to use PIL because everything else in this script is already coded with PIL.