List Info

Thread: How to overlay a mostly transparent image over another image?




How to overlay a mostly transparent image over another image?
country flaguser name
United States
2007-02-16 13:29:03
I have a bunch of 50x50 PNG files that show a little
product.  I have
some other 50x50 PNG files that are transparent except for
the bottom
right corner, which has some text like "new!" or
"fun!".

I want to create a new file that contains the original
product
thumbnail, plus the mostly transparent image added over.

I figure this is a very straightforward operation, but I'm
not getting
anywhere yet.

This is what I've tried so far:

    In [93]: a = Image.open('a.png')

    In [94]: a.info
    Out[94]: {}

    In [95]: a.size
    Out[95]: (50, 50)

    In [96]: a.mode
    Out[96]: 'RGB'

    In [97]: ff = Image.open('freeframe.png')

    In [98]: ff.info
    Out[98]:
    {'Creation Time': '02/16/07',
     'Software': 'Macromedia Fireworks 8',
     'dpi': (71, 71),
     'transparency': 0}

    In [99]: ff.mode
    Out[99]: 'P'

    In [100]: ff.size
    Out[100]: (50, 50)

    In [101]: ImageChops.add(a, ff)
   
------------------------------------------------------------
---------------
    <type 'exceptions.ValueError'>           
Traceback (most recent call last)

    C:Documents and SettingsmwilsonMy
Documentspil-fun<ipython console> in
<module>()

    C:Python25libsite-packagesPILImageChops.py in
add(image1, image2, scale, offset)
        175     image1.load()
        176     image2.load()
    --> 177     return
image1._new(image1.im.chop_add(image2.im, scale, offset))
        178
        179 ##

    <type 'exceptions.ValueError'>: images do not
match

    In [102]: a2 = a.convert(mode='P')

    In [103]: ImageChops.add(a2, ff)
    Out[103]: <Image.Image instance at 0x00EE3F30>

    In [104]: _103.show()

The image that I see is a grayscale image of just the a.png
file.  I
can't see the first image.

I'm probably making lots of rookie mistakes.  All comments
welcome.

Matt

-- 
A better way of running series of SAS programs:
http://overlook.homelinux.net/wilsonwiki/SasAndMakefiles

_______________________________________________
Image-SIG maillist  -  Image-SIGpython.org
htt
p://mail.python.org/mailman/listinfo/image-sig

Re: How to overlay a mostly transparent image over another image?
country flaguser name
United States
2007-02-16 15:07:38
Matthew Wilson <matttplus1.com> wrote:

> I have a bunch of 50x50 PNG files that show a little
product.  I
> have some other 50x50 PNG files that are transparent
except for
> the bottom right corner, which has some text like
"new!" or
> "fun!". 
> 
> I want to create a new file that contains the original
product
> thumbnail, plus the mostly transparent image added
over.
> 
> I figure this is a very straightforward operation, but
I'm not
> getting anywhere yet.
> 
> This is what I've tried so far:
...
> 

Maybe you want im.paste? See the section about it at:

http://effbot
.org/imagingbook/image.htm


max


_______________________________________________
Image-SIG maillist  -  Image-SIGpython.org
htt
p://mail.python.org/mailman/listinfo/image-sig

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )