Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Creating watermark with transparency on jpeg using PIL?

Reply
Thread Tools

Creating watermark with transparency on jpeg using PIL?

 
 
tvmaly@gmail.com
Guest
Posts: n/a
 
      08-18-2005
I have been trying to add a watermark to a jpeg using PIL, but the
watermark has a black box around it. I looked at

http://aspn.activestate.com/ASPN/Coo.../Recipe/362879

and

http://mail.python.org/pipermail/pyt...ay/003369.html

but I think these only refer to gif or png. I know jpegs really do not
support transparency, but is there some way to take a watermark in a
non jpeg format and add it to a jpeg without that box appearing around
it?

Best Regards

Ty

 
Reply With Quote
 
 
 
 
Terry Hancock
Guest
Posts: n/a
 
      08-18-2005
On Thursday 18 August 2005 10:07 am, http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I have been trying to add a watermark to a jpeg using PIL, but the
> watermark has a black box around it. I looked at

[...]
> but I think these only refer to gif or png. I know jpegs really do not
> support transparency, but is there some way to take a watermark in a
> non jpeg format and add it to a jpeg without that box appearing around
> it?


Jpeg is a lossy compression format. You shouldn't do image processing
in such a format at all. Convert the data to PNG, do your processing,
and convert back to JPG for delivery. PIL can do that.

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks http://www.anansispaceworks.com

 
Reply With Quote
 
 
 
 
Max Erickson
Guest
Posts: n/a
 
      08-20-2005
You need to pass a mask in when you paste in the watermark.

see the documentation for the paste method at
http://effbot.org/imagingbook/image.htm
for more information

This should at least get you started...

>>> import Image
>>> import ImageDraw
>>> import ImageFont
>>> import ImageEnhance
>>> im=Image.new('RGB',(300,300),(0,0,0))
>>> font=ImageFont.truetype('verdana.ttf',12)
>>> wm=Image.new('RGBA',(100,50),(255,255,255))
>>> im=Image.new('RGB',(300,300),(255,255,255))
>>> draw=ImageDraw.Draw(wm)
>>> draw.text((0,0),'Watermark',(0,0,0),font)
>>> wm.show()
>>> en=ImageEnhance.Brightness(wm)
>>> mask=en.enhance(0.5)
>>> im.paste(wm,(25,25),mask)
>>> im.show()
>>>


Here, the alpha channel of 'mask' is used as the mask.

max

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a 24-bit PNG with binary transparency? Leif K-Brooks HTML 7 07-20-2009 09:40 AM
displaying jpeg with transparency News KF Java 3 09-19-2005 07:02 PM
Watermark images using PIL Thomas Python 0 11-17-2004 11:11 PM
Exiff-jpeg and jpeg certsnsearches Digital Photography 2 01-07-2004 08:13 PM
huge jpeg files show as very small thumbnails (canon 300d, JPEG) kl Digital Photography 6 11-12-2003 08:11 PM



Advertisments