Python Pillow: Make gradient for transparency
问题 I have code which add gradient on image. def st(path, gradient_magnitude=2.): im = Image.open(path) if im.mode != 'RGBA': im = im.convert('RGBA') width, height = im.size gradient = Image.new('L', (width, 1), color=0xFF) for x in range(width): gradient.putpixel((x, 0), int(255 * (1 - gradient_magnitude * float(x) / width))) alpha = gradient.resize(im.size) black_im = Image.new('RGBA', (width, height), color=0x000000) black_im.putalpha(alpha) gradient_im = Image.alpha_composite(im, black_im)