473,246 Members | 1,417 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,246 software developers and data experts.

Creating watermark with transparency on jpeg using PIL?

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

Aug 18 '05 #1
2 4908
On Thursday 18 August 2005 10:07 am, tv****@gmail.com 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

Aug 18 '05 #2
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

Aug 20 '05 #3

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

Similar topics

1
by: Derek | last post by:
I wanted to know if anyone had any insight or sample code of creating an AVI file from a directory of JPEG images. I have read the thread that that speaks about creating a MOV file from JPEG images...
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...
4
by: Chamomile | last post by:
Does anyone know if its possible to set imagecreatetruecolor() to initialise with transparency rather than black? Maybe a cunning work-around?
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...
4
by: tshad | last post by:
I am trying to set up an Image authorization where you type in the value that is in a picture to log on to our site. I found a program that is supposed to do it, but it doesn't seem to work. ...
0
by: ameshkin | last post by:
Hi, Im pretty new at PHP and need help with something very simple. I wrote a function which watermarks an image. The function works, but i can't figure out how to output the image into a file. ...
9
by: Chuck Anderson | last post by:
Is it possible to overlay a transparent watermark on an image - dynamically? I'd like the result to look like this example: <http://www.cycletourist.com/temp/photo.php> That is a bit of...
5
by: Tem | last post by:
I need to write a custom handler when the handler is accessed, it returns the photo in jpg with 2 lines on the bottom of the image. lower left "Taken by" lower right "January 2 2008" This is...
1
by: rfr | last post by:
Apparently the Transitional Doctype kills this script because the script does not make proper use of units like "px". It works well without a doctype statement. But once someone adds a...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.