image resize question
tim.arnold at sas.com
Fri Oct 19 15:03:30 CEST 2007
"Matimus" <mccredie at gmail.com> wrote in message
news:1192741477.416784.279530 at t8g2000prg.googlegroups.com...
> On Oct 18, 11:56 am, "Tim Arnold" <tim.arn... at sas.com> wrote:
>> Hi, I'm using the Image module to resize PNG images from 300 to 100dpi
>> use in HTML pages, but I'm losing some vertical and horizontal lines in
>> images (usually images of x-y plots).
>> Here's what I do:
>> import Image
>> def imgResize(self,filename):
>> img = Image.open(filename)
>> dpi = img.info.get('dpi')
>> if dpi and 295 < int(dpi) < 305:
>> wd = img.size/3.0 #convert from 300dpi to 100dpi
>> ht = img.size/3.0
>> newimg= img.resize((int(wd),int(ht)))
>> Can someone point me to a better way so I don't lose the reference lines
>> the images?
>> --Tim Arnold
> Resize accepts a second parameter that is used to determine what kind
> of downsampling filter to use (http://www.pythonware.com/library/pil/
> handbook/image.htm). The default is Image.NEAREST, which just samples
> the nearest pixel and results in the type of data loss you are seeing.
> If you want something better try one of the following and see which
> works best for you: Image.BILINEAR, Image.BICUBIC or Image.ANTIALIAS.
> newimg = img.resize((int(wd),int(ht)),Image.ANTIALIAS)
Thank you! The ANTIALIAS filter works great. With any of the others, I still
lost my reference lines.
More information about the Python-list