473,785 Members | 2,465 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(file name)
dpi = img.info.get('d pi')
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(fil ename)

imgResize('myim age.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 2515
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(file name)
dpi = img.info.get('d pi')
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(fil ename)

imgResize('myim age.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)),I mage.ANTIALIAS)
....

Matt

Oct 18 '07 #2
"Matimus" <mc******@gmail .comwrote in message
news:11******** **************@ t8g2000prg.goog legroups.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(file name)
dpi = img.info.get('d pi')
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(fil ename)

imgResize('myi mage.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)),I mage.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
6221
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 the text, but never on the same level. Question: how can i get the image and the text on the same level?? Question 2:
21
3076
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 it using DirectX. I downloaded already the DSK etc, but I can't find how I need to draw an image on a given position. I don't need stuff to write advanced 3D-games, just painting that image. Can anybody help me with this? I'm already looking for...
8
4819
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 clicks the "gallery" link, a cgi script could search the gallery/ dir, and create thumbnails of any jpeg images that don't already have a thumbnail associated with them. The script could then generate a page of clickable thumbnails. A few questions:
15
5366
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 path of the uploaded image, and resize it with the provided dimensions. My function is below. The current function is returning an error when run from the upload function: A generic error occurred in GDI+. Not sure what exactly that means. From what...
2
20910
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 would be appreciated. I've been trying numerous ways to resize images, as I want to make store thumbnails, not full images in my database. -----------------------------------------------------------------------------
3
2379
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) filename = fields.getlist('src')
8
9430
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 rotate the image by 90 deg. They are two differennt files i.e. resize.php and rotate.php. What I want to do is to combine both rotate.php & resize.php files, so when the script resized the image than it will call rotate script to rotate the...
9
4457
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.. Can you help me/point me to the right direction..? Thank you very much in advance..
14
3727
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 anything except for: $image->load('picture.jpg'); $image->resize(546,403); $image->save('picture2.jpg'); I put the variables i need in there within " " instead of ' ' and i always get a error message.....am i doing something or cant...
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10357
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10163
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10104
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9959
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5397
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4063
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.