With PIL... paste image on top of other with dropshadow

P

Peter Bengtsson

I love the dropshadow effect I managed to make with this recipe:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/474116

Here's what it can look like:
http://www.peterbe.com/test/188-tequilacat.2.jpg

It takes a background as a parameter but it's just a colour. What I
want is to put the image on top of another but doing so with a
dropshadow. I guess the solution would be something like putting the
dropshadow on the first image without a background colour but instead
a transparant background and then paste this onto another image.

I just have no idea to do that?

The final result I want is something like programmtically fake that a
picture (the foreground) is hanging on a wall (the background) with a
dropshadow so that it looks like it's hanging in a inch-deep frame.
 
M

Matimus

two things,

change the following line:
Code:
  back = Image.new(image.mode, (totalWidth, totalHeight), background)
To:
Code:
  back = Image.new("RGBA", (totalWidth, totalHeight), background)

and then do something like this:
Code:
  import sys

  bg = Image.open(sys.argv[1])
  image = Image.open(sys.argv[2])

  image = dropShadow(image,shadow=(0x00,0x00,0x00,0xff))
  bg.paste( image, (50,50), image )

  bg.show()

Where the shadow color specifies an alpha transparency value.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top