Reputation: 381
I am using a raspberry Pi with a camera module. I wrote a script which made the camera module take a picture.
Now, after I took the picture I need a Python script which puts the recently taken picture and another picture (something like a watermark or logo) together. I tried to use this: http://pillow.readthedocs.org/en/latest/handbook/tutorial.html , but I don't know which commands or syntax I must use.
EDIT:
My Python script... It takes a picture with the time.
from datetime import datetime
zeit = datetime.now()
zeit = "%s-%s-%s-%s:%s:%s" % (zeit.year,zeit.day,zeit.month,zeit.hour,zeit.minute,zeit.second)
Bildformat = ".png"
Bildname = "Bild-" + zeit + Bildformat
from subprocess import call
#call (["raspistill -o " + Bildname + " -t 1 -n"], shell=True)
call (["raspistill -o /home/pi/cam_project/Bilder/" + Bildname + " -t 1 -n"], shell=True)
EDIT 2:
Thanks for your Answers. This is my whole Code. I want to add something like in the Tutorial (look at the link above). The main Idea is that the camera shoots a picture and the PIL library (see link) grabs the picture and add this recently taken picture to another picture (which I made before and this is in the same directory (Like a watermark or logo))
Something like:
from __future__ import print_function
from PIL import Image
img_taken = Image.open("/home/pi/cam_project/Bilder/" + Bildname + "")
# This is the picture with the date as name
img_watermark/logo = Image.open("home/pi/cam_project/Bilder/watermark.png
# This is the logo
# Then I want something like: paste img_watermark/logo in img_taken
If you click the link I posted above and scroll down to "Rolling an Image" After the code they say:
For more advanced tricks, the paste method can also take a transparency mask as an optional argument. In this mask, the value 255 indicates that the pasted image is opaque in that position (that is, the pasted image should be used as is). The value 0 means that the pasted image is completely transparent. Values in-between indicate different levels of transparency.
As output I want the processed picture (with the logo/watermark)
Upvotes: 1
Views: 2757
Reputation: 7545
I think this will work for you. It can handle transparency in the watermark image you use and also make the watermark image brighter so it's not as visible.
import PIL.Image
import PIL.ImageEnhance
# images
base_path = 'base.jpg'
watermark_path = 'watermark.png'
base = PIL.Image.open(base_path)
watermark = PIL.Image.open(watermark_path)
# optional lightness of watermark from 0.0 to 1.0
brightness = 0.5
watermark = PIL.ImageEnhance.Brightness(watermark).enhance(brightness)
# apply the watermark
some_xy_offset = (10, 20)
# the mask uses the transparency of the watermark (if it exists)
base.paste(watermark, some_xy_offset, mask=watermark)
base.save('final.png')
base.show()
(public domain cat image)
Upvotes: 4