473,287 Members | 3,295 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

image resize question

Hi, I'm using the Image module to resize PNG images from 300 to 100dpi for
use in HTML pages, but I'm losing some vertical and horizontal lines in the
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[0]) < 305:
wd = img.size[0]/3.0 #convert from 300dpi to 100dpi
ht = img.size[1]/3.0
newimg= img.resize((int(wd),int(ht)))
newimg.save(filename)

imgResize('myimage.png')

Can someone point me to a better way so I don't lose the reference lines in
the images?
thanks,
--Tim Arnold
Oct 18 '07 #1
2 2472
On Oct 18, 11:56 am, "Tim Arnold" <tim.arn...@sas.comwrote:
Hi, I'm using the Image module to resize PNG images from 300 to 100dpi for
use in HTML pages, but I'm losing some vertical and horizontal lines in the
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[0]) < 305:
wd = img.size[0]/3.0 #convert from 300dpi to 100dpi
ht = img.size[1]/3.0
newimg= img.resize((int(wd),int(ht)))
newimg.save(filename)

imgResize('myimage.png')

Can someone point me to a better way so I don't lose the reference lines in
the images?
thanks,
--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.

example:
....
newimg = img.resize((int(wd),int(ht)),Image.ANTIALIAS)
....

Matt

Oct 18 '07 #2
"Matimus" <mc******@gmail.comwrote in message
news:11**********************@t8g2000prg.googlegro ups.com...
On Oct 18, 11:56 am, "Tim Arnold" <tim.arn...@sas.comwrote:
>Hi, I'm using the Image module to resize PNG images from 300 to 100dpi
for
use in HTML pages, but I'm losing some vertical and horizontal lines in
the
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[0]) < 305:
wd = img.size[0]/3.0 #convert from 300dpi to 100dpi
ht = img.size[1]/3.0
newimg= img.resize((int(wd),int(ht)))
newimg.save(filename)

imgResize('myimage.png')

Can someone point me to a better way so I don't lose the reference lines
in
the images?
thanks,
--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.

example:
...
newimg = img.resize((int(wd),int(ht)),Image.ANTIALIAS)
...

Matt
Thank you! The ANTIALIAS filter works great. With any of the others, I still
lost my reference lines.
--Tim
Oct 19 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Hugo de Payns | last post by:
Happy newyear first of all; I am experimenting with a list and some images; the problem is text and the (LI)image are never outlined, or the image is higher than the text, or the image is below...
21
by: DraguVaso | last post by:
Hi, I have an inherited DataGrid, that does lots of extra stuff. For exemple drawing a backgroundimage in every cell. The problem is that it's taking too much time (using gdi+), so I want to do...
8
by: Chris Dewin | last post by:
Hi. I run a website for my band, and the other guys want an image gallery. I'm thinking it would be nice and easy, if we could just upload a jpg into a dir called "gallery/". When the client...
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
2
by: Dominic Vella | last post by:
Hi, I know I seem to have the really complicated questions, but I guess that's why I'm here. This is a little verbose, only because I've been trying to crack this for a week now. Your help...
3
by: danielatdaveschool | last post by:
Hi, noob here Im using mod_python and apache2 using psp for output of page, i open a file and resize it with the following code <% import Image, util fields = util.FieldStorage(req)...
8
by: infoseekar | last post by:
Image Resize & Rotation Hi I have 2 scripts, one for Image rotation and other image resize and they both are working. Image resize scripts load the picture and resize it and Image rotation...
9
by: pek | last post by:
Here is what I want: I have an image, let's say a JPEG 800x600... I want to create a transparent 128x128 PNG image and then resize the 800x600 to fit in the center of my transparent 128x128 PNG.....
14
anfetienne
by: anfetienne | last post by:
hi.....i have this script (below #1) that is linked to another php file SimpleImage.php (#2) im trying to get it to work on my uploaded images but it keeps coming up errors.....i haven't altered...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.