Watermarking Tiles in TileCache

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Watermarking Tiles in TileCache

Andrew Hughes-2
Hi All,

Some tile sources do not provide water marking of their images... or
even very simple text based watermarking that looks terrible. Firstly,
this is is not difficult to implement and I have attatched python code
that does just this. Even I know very little python but the attached
code does work.

I understand that this is bespoke functionality, however I would like to
offer it to the community/MetaCarta as a contribution. Integration of
this into TileCache could be very easy.... Suggestively the [Layer]
would have a new non-mandatory parameter
"watermarkImage=/path/to/some/image.png" (a 256 x 256 image as default).
In the presence of this parameter each tile (after any metaTile has been
cut up) has this watermark applied with the attatched code, and
persisted to cache with watermark.

This is low cost functionality that shouldn't introduce any new
maintainance issues, and I would be happy to contribute if a Sandbox is
made available. I would rather not diverge, it's a last resort.


--AH

------------------------------------------------------------------------------------------------------------------------------------------------

import Image, ImageEnhance

def reduce_opacity(im, opacity):
    """Returns an image with reduced opacity."""
    assert opacity >= 0 and opacity <= 1
    if im.mode != 'RGBA':
        im = im.convert('RGBA')
    else:
        im = im.copy()
    alpha = im.split()[3]
    alpha = ImageEnhance.Brightness(alpha).enhance(opacity)
    im.putalpha(alpha)
    return im

def watermark(im, mark, position, opacity=1):
    """Adds a watermark to an image."""
    if opacity < 1:
        mark = reduce_opacity(mark, opacity)
    if im.mode != 'RGBA':
        im = im.convert('RGBA')
    layer = Image.new('RGBA', im.size, (0,0,0,0))
    layer.paste(mark, position)
    return Image.composite(layer, im, layer)

def test():
    im = Image.open('Input.jpeg')
    mark = Image.open('Watermark.png')
    watermark(im, mark, (0,0), 0.5).save('Output.jpeg')

if __name__ == '__main__':
    test()




_______________________________________________
Tilecache mailing list
[hidden email]
http://openlayers.org/mailman/listinfo/tilecache
Reply | Threaded
Open this post in threaded view
|

Re: Watermarking Tiles in TileCache

Christopher Schmidt-2
On Tue, May 01, 2007 at 01:46:52PM +0930, Andrew Hughes wrote:
> Hi All,
>
> Some tile sources do not provide water marking of their images... or
> even very simple text based watermarking that looks terrible. Firstly,
> this is is not difficult to implement and I have attatched python code
> that does just this. Even I know very little python but the attached
> code does work.

The Python looks pretty decent -- no complaints.

> I understand that this is bespoke functionality, however I would like to
> offer it to the community/MetaCarta as a contribution. Integration of
> this into TileCache could be very easy....

So long as the default path avoids this code, I'm willing to integrate
it. In addition to the 'watermarkImage' parameter, I think an
'watermarkOpacity' parameter should also be made available. If you could
write a patch to the TC code, then upload it to trac
(http://dev.tilecache.org/) and let me know, I'll take a look at it
then.

Thanks,
--
Christopher Schmidt
MetaCarta
_______________________________________________
Tilecache mailing list
[hidden email]
http://openlayers.org/mailman/listinfo/tilecache
Reply | Threaded
Open this post in threaded view
|

Re: Watermarking Tiles in TileCache

Andrew Hughes-2
Hey All,

Watermaking Patch is now available:
The only difference between the patches is that the FINAL also has an update for the README.

Finally....

Thanks for your support over the past few months! This patch is not much... and its taken me a while to become useful but I hope this is the first of many contributions I can make.

--AH


Christopher Schmidt wrote:
On Tue, May 01, 2007 at 01:46:52PM +0930, Andrew Hughes wrote:
  
Hi All,

Some tile sources do not provide water marking of their images... or 
even very simple text based watermarking that looks terrible. Firstly, 
this is is not difficult to implement and I have attatched python code 
that does just this. Even I know very little python but the attached 
code does work.
    

The Python looks pretty decent -- no complaints.

  
I understand that this is bespoke functionality, however I would like to 
offer it to the community/MetaCarta as a contribution. Integration of 
this into TileCache could be very easy.... 
    

So long as the default path avoids this code, I'm willing to integrate
it. In addition to the 'watermarkImage' parameter, I think an
'watermarkOpacity' parameter should also be made available. If you could
write a patch to the TC code, then upload it to trac
(http://dev.tilecache.org/) and let me know, I'll take a look at it
then.

Thanks,
  



_______________________________________________
Tilecache mailing list
[hidden email]
http://openlayers.org/mailman/listinfo/tilecache
Reply | Threaded
Open this post in threaded view
|

Re: Watermarking Tiles in TileCache

Christopher Schmidt-2
On Thu, May 03, 2007 at 03:05:23PM +0930, Andrew Hughes wrote:

> Hey All,
>
> Watermaking Patch is now available:
>
>    * Trac Ticket #8
>          o http://dev.tilecache.org/ticket/8
>    * SVN Patch (Based on trunk)
>          o
>          http://dev.tilecache.org/attachment/ticket/8/ticket_8_watermarking_patch_FINAL.txt
>
> The only difference between the patches is that the FINAL also has an
> update for the README.

Just as a minor review thing: in the future, you should always update
your SVN before making patches. (Usually this is 'update' in a dropdown,
or 'svn up' at the command line.) The patch you provided reverts
existing changes to the ImageLayer code that were likely added after you
initially checked out.

Other than that, this looks good. Nice work stumbling thruogh the config
parsing to find everything you needed :) I'm willing to apply this to
trunk and kick out a 1.8, but:

"If you haven't contributed before, fill out an ICLA[1] or CCLA[2] regarding
the work." -- http://dev.tilecache.org/

If you can get me one of those (to [hidden email]), I'll go ahead
and drop the patch in.

[1] http://tilecache.org/icla.txt
[2] http://tilecache.org/ccla.txt

Regards,
--
Christopher Schmidt
MetaCarta
_______________________________________________
Tilecache mailing list
[hidden email]
http://openlayers.org/mailman/listinfo/tilecache