472,964 Members | 2,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

PIL GIF transparency

Hello alll,

Apologies if this isn't the correct list.

I'm getting my feet wet with the Python Imaging Library (PIL) 1.1.6 on
Python 2.5.1. I have played around quite a bit with transparent GIFs,
and from what I can tell, PIL should support what I want to do -
except I can't seem to get it to work.

I have a large number of smallish icons (GIFs with transparency) that
I'd like to tile into a grid in one large GIF image. The background
color of the image should be GIF-transparent. Currently, I can set it
to be white or black or any other color I want, just not transparent.
My current code:

import os, sys
from PIL import Image, ImageColor

# size in pixels of each row/col
ROWSIZE = 50
COLSIZE = 50

# maxwidth of sprite grid
SPRITEWIDTH = 20
MAXWIDTH = COLSIZE*SPRITEWIDTH

FILENAME = '/static/images/icons.gif'

def merge():
pwd = os.getcwd()
imagePath = os.path.join(pwd, 'images')

# Somehow, I need to ensure the palette used in the sprite image
# is the same as the individual icons
sprites = Image.new('RGBA', (MAXWIDTH, MAXWIDTH), (253,253,253,0))
sprites.putalpha(0)

palette = None
colors = []
col = 10
row = 10

for f in os.listdir(imagePath):
try:
im = Image.open(os.path.join(imagePath, f))

if im.size[0] <= 20 and im.size[1] <= 20 and im.format ==
'GIF':
sprites.paste(im.copy(), (col, row))
print 'url(/static/images/%s) =url(%s) -%dpx -%dpx'
% (f, FILENAME, col, row)
col += COLSIZE
if col >= MAXWIDTH:
row += ROWSIZE
col = 10

if row >= sprites.size[1]:
break

except IOError, ex:
pass

sprites = sprites.crop((0,0,MAXWIDTH, row)).point(lambda pt: pt ==
(253, 253, 253, 0) and 0 or pt)
return sprites

So this code is obviously littered with the detritus of failed
attempts to get transparency to work. Has anyone out there had any
experience with this?

Thanks,

David

Sep 25 '07 #1
1 4498
En Mon, 24 Sep 2007 21:53:46 -0300, David <da******@gmail.comescribi�:
I have a large number of smallish icons (GIFs with transparency) that
I'd like to tile into a grid in one large GIF image. The background
color of the image should be GIF-transparent. Currently, I can set it
to be white or black or any other color I want, just not transparent.
Read this post from 2006:
<http://groups.google.com/group/comp.lang.python/msg/9c33aea70b72d78b>

--
Gabriel Genellina

Sep 25 '07 #2

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

Similar topics

2
by: Cecile Muller | last post by:
I've been trying to just open a png and display it, that way: <? header ("Content-type: image/png"); $im = imagecreatefrompng('empty.png'); imagepng($im); ?> But the transparency is not...
57
by: Piotr Wolski | last post by:
how to make my page that it was correct with every browser standard? for example when i change HTML's table size it has no effect when i see it under mozilla and has effect under Internet...
4
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);...
2
by: Robin Becker | last post by:
Has anyone done transparency with PIL & TIFF? I'm using PIL to generate a preview TIFF for embedding into an eps file and am being asked for the TIFF to support transparency. -- Robin Becker
3
by: Mr. x | last post by:
Hello, I would like that my image's background color will be transparent. What I have is only paintbrush. My image is *.jpg format (I have tried to save it as *.gif format, and I got less...
20
by: Nathan Sokalski | last post by:
I am trying to create graphics with GDI+ that include transparency. However, the transparency never seems to show up, even though my colors have an alpha value of 0. How can I generate a graphic...
6
by: tommaso.gastaldi | last post by:
In a previous post I have been asking about a way to test Alpha Transparency. Bob and Michael have kindly provided some ideas. Here I would like to share the function I have prepared, for the...
0
by: ZikO | last post by:
Hi. I've experienced one problem. Im using three froms. Two of them are maximized, whereas one is normal form with transparency. Transparency stops working, that is I can see the color which...
1
by: dragze | last post by:
Hi, On one of the pages of my site i use two javascripts, one makes transparency of png's work in IE, and the other embeds a flash player. Now use one of the scripts it works fine, use both and...
3
by: Martijn Mulder | last post by:
When I populate a ToolStrip with ToolStripButtons with a .png-image on it, will Windows understand the transparency of the .png file?
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

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.