[Image-SIG] resizing an image with alphachannel: dirty edges
ivangermes at gmail.com
Fri Nov 27 15:59:23 CET 2009
It's works fine!
2009/11/20 Alexey Borzenkov <snaury at gmail.com>
> On Thu, Nov 12, 2009 at 3:59 PM, Ivan Elchin <ivangermes at gmail.com> wrote:
> > I have a problem, when i resizing an image with alphachannel.
> You can try converting your image to RGBa (premultiplied alpha),
> resizing it, then converting back to RGBA. The problem here is that
> there are dirty pixels with 0 alpha, and they get interpolated like
> everything else. On my PIL this works:
> from PIL import Image
> im = Image.open("sega.png")
> im = im.convert("RGBa")
> cur_width, cur_height = im.size
> new_width, new_height = (200, 200)
> if not new_width == 0 and not new_height == 0:
> ratio = min(float(new_width)/cur_width,
> if new_width == 0:
> ratio = float(new_height)/cur_height
> ratio = float(new_width)/cur_width
> new_dimensions = (int(round(cur_width*ratio)),
> new_im = im.resize(new_dimensions, Image.ANTIALIAS)
> new_im = new_im.convert("RGBA")
> Though my PIL has many modifications, I'm not sure if RGBA->RGBa->RGBA
> is implemented in vanilla 1.1.6. (after checking) Ah, yes, it's not.
> Though you can try recompiling PIL with this patch:
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Image-SIG