Watermarking with Image Composite

386 views
Skip to first unread message

Mick

unread,
May 23, 2009, 10:41:55 PM5/23/09
to Google App Engine
Hello,

I'm trying to create a watermark on an image by using the app engine
images composite function. However the function doesn't seem to
respect the transparency in my overlay image, which is just a
copyright symbol. It fills the transparent area with white so the
final output looks like this http://bayimg.com/image/eaaagaacb.jpg. I
have tried all sorts of combinations for opacity and image types but
nothing seems to work right. Please advise.

[code]
def post(self):
im = avatar = self.request.get("image")
image = images.Image(im)


result = urlfetch.Fetch('http://upload.wikimedia.org/wikipedia/
commons/5/58/Red_copyright.png')
copyright = result.content
new_image = images.composite([
(im, 0 ,0, 1.0, images.TOP_LEFT),
(copyright, 0 ,0, 0.5, images.CENTER_CENTER)],
image.width,
image.height,
0,
images.PNG)
self.response.headers['Content-Type'] = "image/png"
self.response.out.write(new_image)

Nick Johnson (Google)

unread,
May 26, 2009, 7:53:19 PM5/26/09
to google-a...@googlegroups.com
Hi Mick,

Have you tried this on appspot? There's a known bug in the
dev_appserver whereby it ignores transparency for image.composite, but
it should work fine in production.

-Nick Johnson

Mick

unread,
Jun 3, 2009, 6:44:45 PM6/3/09
to Google App Engine
No I haven't but now that you mentioned I will give it a try. Could
you point me to the bug?

Thanks,
Mick

On May 26, 7:53 pm, "Nick Johnson (Google)" <nick.john...@google.com>
wrote:
> Hi Mick,
>
> Have you tried this on appspot? There's a known bug in the
> dev_appserver whereby it ignores transparency for image.composite, but
> it should work fine in production.
>
> -Nick Johnson
>
>
>
> On Sat, May 23, 2009 at 7:41 PM, Mick <mickler...@gmail.com> wrote:
>
> > Hello,
>
> > I'm trying to create a watermark on an image by using the app engine
> > images composite function. However the function doesn't seem to
> > respect the transparency in my overlay image, which is just a
> > copyright symbol. It fills the transparent area with white so the
> > final output looks like thishttp://bayimg.com/image/eaaagaacb.jpg. I

Mick

unread,
Jun 3, 2009, 7:08:36 PM6/3/09
to Google App Engine
Just tested and it worked on appspot. awesome! but is there a
workaround to get it work correctly on dev?

Rodrigo Moraes

unread,
Jul 30, 2009, 10:40:53 PM7/30/09
to Google App Engine
On Jun 3, 8:08 pm, Mick wrote:
> Just tested and it worked on appspot. awesome! but is there a
> workaround to get it work correctly on dev?

Hi Mick.
I had this same problem today (no transparency in png's when using
composite()), and got a quick fix. If you want to pach the SDK until
it is fixed, here's how.

in google.appengine.api.images.images_stub.py, on lines 114-116,
you'll find:

alpha = options.opacity() * 255
mask = Image.new("L", source.size, alpha)
canvas.paste(source, (x_offset, y_offset), mask)

replace it with...

if source.mode == 'RGBA':
canvas.paste(source, (x_offset, y_offset), source)
else:
alpha = options.opacity() * 255
mask = Image.new("L", source.size, alpha)
canvas.paste(source, (x_offset, y_offset), mask)

that's it.
-- rodrigo

Nickolas Daskalou

unread,
Feb 5, 2010, 2:04:27 AM2/5/10
to Rodrigo Moraes, google-a...@googlegroups.com
Hey Google, has this been fixed in the new SDK?


On Jul 31 2009, 1:40 pm, Rodrigo Moraes <rodrigo.mor...@gmail.com>
wrote:

Nickolas Daskalou

unread,
Feb 16, 2010, 10:27:38 PM2/16/10
to Google App Engine
*BUMP*


On Feb 5, 6:04 pm, Nickolas Daskalou <n...@daskalou.com> wrote:
> Hey Google, has this been fixed in the new SDK?
>
> On Jul 31 2009, 1:40 pm, Rodrigo Moraes <rodrigo.mor...@gmail.com>
> wrote:
>
> > On Jun 3, 8:08 pm, Mick wrote:
>
> > > Just tested and it worked on appspot. awesome! but is there a
> > > workaround to get it work correctly on dev?
>
> > Hi Mick.
> > I had this same problem today (no transparency in png's when using
> > composite()), and got a quick fix. If you want to pach the SDK until
> > it is fixed, here's how.
>
> > in google.appengine.api.images.images_stub.py, on lines 114-116,
> > you'll find:
>

> >      alpha= options.opacity() * 255


> >       mask = Image.new("L", source.size,alpha)
> >       canvas.paste(source, (x_offset, y_offset), mask)
>
> > replace it with...
>
> >       if source.mode == 'RGBA':
> >           canvas.paste(source, (x_offset, y_offset), source)
> >       else:

> >          alpha= options.opacity() * 255


> >           mask = Image.new("L", source.size,alpha)

Nickolas Daskalou

unread,
Feb 16, 2010, 10:42:23 PM2/16/10
to Google App Engine
Answer: No. However, Rodrigo's fix still works with SDK 1.3.1.


*BUMP*
--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To post to this group, send email to google-a...@googlegroups.com.
To unsubscribe from this group, send email to google-appengi...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.


Reply all
Reply to author
Forward
0 new messages