473,508 Members | 2,226 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.tif"
im = Image.open("tmp/tmsho20080901.tif")
w, h = im.size

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

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

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

convert -colors 256 -resize 600 -colorspace RGB -black-threshold 100 -
contrast -intent Perceptual tmp/tmsho20080901.tif tmsho20080901.gif

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 1746
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.tif"
im = Image.open("tmp/tmsho20080901.tif")
w, h = im.size
im.thumbnail((600, 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("tmsho20080901.gif")
....
Using ImageMagick's convert I would do this...

convert -colors 256 -resize 600 -colorspace RGB -black-threshold 100 -
contrast -intent Perceptual tmp/tmsho20080901.tif tmsho20080901.gif

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.tif")
w, h = im.size
im.thumbnail((600, h * 600 // w),
Image.ANTIALIAS).save("tmp/sho20080901.png")

--Scott David Daniels
Sc***********@Acm.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.tif"
im = Image.open("tmp/tmsho20080901.tif")
w, h = im.size
im.thumbnail((600, 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("tmsho20080901.gif")

...
Using ImageMagick's convert I would do this...
convert -colors 256 -resize 600 -colorspace RGB -black-threshold 100 -
contrast -intent Perceptual tmp/tmsho20080901.tif tmsho20080901.gif
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.tif")
* * *w, h = im.size
* * *im.thumbnail((600, h * 600 // w),
* * * * * * * * * Image.ANTIALIAS).save("tmp/sho20080901.png")

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

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

Similar topics

4
2847
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...
0
1871
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. ...
4
3300
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);...
0
2160
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....
10
2288
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...
86
7680
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:...
3
1794
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...
5
6176
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...
0
7225
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,...
0
7326
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,...
0
7383
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...
1
7046
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...
0
7498
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...
1
5053
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...
0
4707
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...
0
3182
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.