sorl.thumbnail processor: white background

1
2
3
4
5
6
7
8
from PIL import Image, ImageColor
def white_background(im, requested_size, opts):
    try:
        background = Image.new('RGB', im.size, ImageColor.getcolor('white', 'RGB'))
        background.paste(im, mask=im.split()[3])
        return background
    except:
        return im

Comments

(Forgotten your password?)

You may use Markdown syntax here, but raw HTML will be removed.