473,569 Members | 2,590 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Resizing Tif's to smaller gifs adds pixels

I'm not entirely sure how this group works: if there is a page I'm
supposed to follow up on or if I should expect an email in reply.
Anyway, here's my question.

I'm very new to Python and PIL, I know how to do this stuff in perl
and ImageMagick, but I'm having issues with Python and PIL.

I need to scale a TIFF image from 1925x588 px to a GIF of 600xnnn px.

I've tried the following code, but it leads to a lot of extra odd
colored pixels being inserted into the resulting image.

img = "tmp/tmsho20080901.t if"
im = Image.open("tmp/tmsho20080901.t if")
w, h = im.size

im.thumbnail((6 00, h * 600 / w), Image.ANTIALIAS )

newimg = im.resize((600, int(h * (600.0 / w))), Image.ANTIALIAS )
newimg.save("tm sho20080901.gif ")

Using ImageMagick's convert I would do this...

convert -colors 256 -resize 600 -colorspace RGB -black-threshold 100 -
contrast -intent Perceptual tmp/tmsho20080901.t if tmsho20080901.g if

I think it may have something to do with the palette or the number of
colors alotted for the resulting image, but I'm really not a graphics
guy.

Any help on this would be appreciated.

Samuel
Oct 21 '08 #1
2 1752
sm************@ gmail.com wrote:
...I need to scale a TIFF image from 1925x588 px to a GIF of 600xnnn px.
I've tried the following code, but it leads to a lot of extra odd
colored pixels being inserted into the resulting image.
img = "tmp/tmsho20080901.t if"
im = Image.open("tmp/tmsho20080901.t if")
w, h = im.size
im.thumbnail((6 00, h * 600 / w), Image.ANTIALIAS )
This line is rather silly, making a result that you drop on the floor.
newimg = im.resize((600, int(h * (600.0 / w))), Image.ANTIALIAS )
newimg.save("tm sho20080901.gif ")
....
Using ImageMagick's convert I would do this...

convert -colors 256 -resize 600 -colorspace RGB -black-threshold 100 -
contrast -intent Perceptual tmp/tmsho20080901.t if tmsho20080901.g if

I think it may have something to do with the palette or the number of
colors alotted for the resulting image, but I'm really not a graphics
guy.
Yep, you are right. The issue is trying to reduce to a 256-color
pallette. Try using '.png' format (portable network graphics), that
allows a full palette for exact pixel images.

Try something like this:
im = Image.open("tmp/tmsho20080901.t if")
w, h = im.size
im.thumbnail((6 00, h * 600 // w),
Image.ANTIALIAS ).save("tmp/sho20080901.png ")

--Scott David Daniels
Sc***********@A cm.Org
Oct 21 '08 #2
Scott,

I appreciate the quick response, but I need this in a GIF format.

Samuel

On Oct 21, 3:46*pm, Scott David Daniels <Scott.Dani...@ Acm.Orgwrote:
smullen.ucl...@ gmail.com wrote:
...I need to scale a TIFF image from 1925x588 px to a GIF of 600xnnn px..
I've tried the following code, but it leads to a lot of extra odd
colored pixels being inserted into the resulting image.
img = "tmp/tmsho20080901.t if"
im = Image.open("tmp/tmsho20080901.t if")
w, h = im.size
im.thumbnail((6 00, h * 600 / w), Image.ANTIALIAS )

This line is rather silly, making a result that you drop on the floor.newimg = im.resize((600, int(h * (600.0 / w))), Image.ANTIALIAS )
newimg.save("tm sho20080901.gif ")

...
Using ImageMagick's convert I would do this...
convert -colors 256 -resize 600 -colorspace RGB -black-threshold 100 -
contrast -intent Perceptual tmp/tmsho20080901.t if tmsho20080901.g if
I think it may have something to do with the palette or the number of
colors alotted for the resulting image, but I'm really not a graphics
guy.

Yep, you are right. *The issue is trying to reduce to a 256-color
pallette. *Try using '.png' format (portable network graphics), that
allows a full palette for exact pixel images.

Try something like this:
* * *im = Image.open("tmp/tmsho20080901.t if")
* * *w, h = im.size
* * *im.thumbnail(( 600, h * 600 // w),
* * * * * * * * * Image.ANTIALIAS ).save("tmp/sho20080901.png ")

--Scott David Daniels
Scott.Dani...@A cm.Org
Oct 21 '08 #3

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

Similar topics

4
2853
by: Ruby Tuesday | last post by:
I have a section(185pixelsx 185pixels) in my web page to display an image that is stored in a directory. Using php, how do you resize so if: the image dimension is smaller(width and height is less than 185pixels), display it in the center of the section if the width OR height is larger than 185pixel, resize them with aspect ratio...
0
1876
by: Michael Rostkowski | last post by:
I posted this in alt.php, but as a reply, so now I'm posting it here for people who might have missed it but still could find it useful. Thanks to Andy Hassall for giving me good information. I compared the smooth image resampling used in PHP to create good quality thumbnails of large images, used commonly in image galleries. i compared...
4
3303
by: Matthias Czapla | last post by:
Hi! I want to resize uploaded GIF images. Currently I do it like this: <?php // ... $img = imagecreatefromgif($path); $img_scaled = imagecreate($new_width, $new_height); imagecopyresampled($img_scaled, $img, 0, 0, 0, 0, $new_width, $new_height, $old_width, $old_height);
0
2166
by: mchl gdbt | last post by:
Hi, I have several thousand tiffs generated by application A which are read by application B. I need to remove a few colours from the tiffs and I decided to try with the python imaging library. Running under debug mode permits saving my tiff files (with Image.DEBUG=0, the save doesn't work! see below) , but it truncates the crazy tags in...
10
2304
by: riki | last post by:
Hi, i have a big problem...i'm using one jscript for resizing of all of my pics in popUp...in main html i'm having many little pics and clicking on them they open in popUp and resize to larger version of the same pic. now, it works fine and sometimes when i click on little one it doesn't resize well... this is the code: main.html
86
7700
by: Michael Kalina | last post by:
Because when I asked for comments on my site-design (Remember? My site, your opinion!) some of you told me never to change anything on font-sizes! What do you guys think of that: http://www.clagnut.com/blog/348/ I hope that's going to be a good discussion! Michael
3
1795
by: engwar | last post by:
I'm writing some file upload code using C# for users on my website. If the image is too large I want to resize it smaller to a thumbnail size. It's working fine for jpegs but the thumbnails of the gifs look pretty bad. I assume it's something to do with the color palette. I don't know a whole lot about graphics programming. Can anyone...
5
6190
by: Maxi | last post by:
I have a 30X16 cells table in my html page. Table height and width are set to 100%. I have set size of every cell inside the table to 24 pixel. When I open the html page in maximize state in either resolution 800 X 600 or 1152 X 864 it takes up the entire explorer size. In screen resolution 800 X 600, if I insert a pictures of 24 X 24...
0
7615
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8130
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...
0
7979
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...
0
6284
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...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
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...
0
3643
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
940
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.