473,404 Members | 2,195 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,404 software developers and data experts.

PIL & TIFF transparency?

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
Jul 18 '05 #1
2 4829
Robin Becker <ro***@jessikat.fsnet.co.uk> wrote in message news:<bP**************@jessikat.fsnet.co.uk>...
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.


Simple example that makes pure white areas of an RGB image transparent
(there's probably a better way to create the mask, and a better way to
add the mask to the image, but this gives you a starting point):

import Image, ImageChops
im = Image.open('/junk/pickme.png')
# create mask (will become alpha band i.e. transparency)
mask = im.point(lambda i : i == 255 and 255) # create RGB mask
mask = mask.convert('L') # mask to grayscale
mask = mask.point(lambda i : i == 255 and 255) # mask to B&W grayscale
mask = ImageChops.invert(mask)
# merge mask with image
R, G, B = im.split()
nuimg = Image.merge('RGBA', (R, G, B, mask))
nuimg.save('/junk/out.tif', 'tiff')

Regards, Myles.
Jul 18 '05 #2
In article <a4**************************@posting.google.com >, Myles
<my***@geocities.com> writes
Robin Becker <ro***@jessikat.fsnet.co.uk> wrote in message news:<bPFXEJAEJ7J$Ewf
Y@jessikat.fsnet.co.uk>...
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.


Simple example that makes pure white areas of an RGB image transparent
(there's probably a better way to create the mask, and a better way to
add the mask to the image, but this gives you a starting point):

import Image, ImageChops
im = Image.open('/junk/pickme.png')
# create mask (will become alpha band i.e. transparency)
mask = im.point(lambda i : i == 255 and 255) # create RGB mask
mask = mask.convert('L') # mask to grayscale
mask = mask.point(lambda i : i == 255 and 255) # mask to B&W grayscale
mask = ImageChops.invert(mask)
# merge mask with image
R, G, B = im.split()
nuimg = Image.merge('RGBA', (R, G, B, mask))
nuimg.save('/junk/out.tif', 'tiff')

Regards, Myles.

thanks very much, I didn't know the TIFF format even supported
transparency till yesterday and now you say the PIL tiff plugin will
handle it ok. Great work pythoneers!
--
Robin Becker
Jul 18 '05 #3

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

Similar topics

1
by: news.microsoft.com | last post by:
Hello group, My goal is to attach an image over another image. Top image should be transparent so the back image is visible through the top one. Bellow is a test code in VB.NET. You need to...
2
by: TC | last post by:
Is there any way to save a bitmap in an uncompressed format which preserves transparency? The BMP format is uncompressed, but doesn't support transparency. The GIF format has an alpha channel,...
0
by: Jean Christophe Avard | last post by:
Hi! I'm designing a clipart manager. It stores TIFF file since the clipart are isolated object (transparent background). The problem is that when I drag the TIFF from my application onto Corel...
1
by: aljosa | last post by:
i'm trying to convert python (image resizer script using PyQt4) script to exe but support for jpeg and tiff image formats is located in Qt4.1\plugins\imageformats (dll files) and when script is...
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...
1
by: Scott Elgram | last post by:
Hello everyone, I'm hoping someone here can pose an alternative that might work better than what I have created so far. I have a web site that needs to deal with Multi-Page TIFF images. ...
1
by: zakk | last post by:
Please help! this is the website: http://www.mbg.ae/services.htm in the Services Drop-down menu in IE the transparency of the sub-menu is showing but when you check this on Firefox there's no...
3
by: GiJeet | last post by:
Hello, we have an app that scans documents into TIFF format and we need to transfer them over the internet. If anyone knows of a SDK we can use that can compress TIFFs on the fly or even if it can...
2
by: soyab husein | last post by:
We have the following input data file: KEY File name OrderNo. 001 001_1.tiff 900001 002 002_1.tiff 900002 002 002_2.tiff 900002 002 002_3.tiff 900002 003 003_1.tiff ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...
0
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...
0
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
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...

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.