6a57709592ac87cddce539a78676127e994bf83d
1 # -*- coding: utf-8 -*-
2 ############################################################
3 # Copyright © 2005-2008 Benoît PIN <benoit.pin@ensmp.fr> #
4 # Plinn - http://plinn.org #
6 # This program is free software; you can redistribute it #
7 # and/or modify it under the terms of the Creative Commons #
8 # "Attribution-Noncommercial 2.0 Generic" #
9 # http://creativecommons.org/licenses/by-nc/2.0/ #
10 ############################################################
13 $Id: difference.py 622 2008-11-16 23:38:18Z pin $
14 $URL: http://svn.luxia.fr/svn/labo/projects/zope/Portfolio/trunk/Extensions/difference.py $
16 from AccessControl
import Unauthorized
17 from PIL
.Image
import new
as newImage
, open as imgopen
, composite
18 from PIL
.ImageChops
import difference
19 from cStringIO
import StringIO
21 def diffImage(self
, image
, image2
, mask
) :
23 if iw
> 800 or ih
> 800 :
24 raise Unauthorized
, "You are not allowed to get an image larger than 800px"
26 mask
= imgopen(StringIO(str(mask
)))
27 assert mask
.mode
=='L', "mask must be in L mode"
29 image2
= imgopen(StringIO(str(image2
)))
30 diffImage
= difference(image
, image2
)
31 mergedImage
= composite(diffImage
, image
, mask
)
33 box
= (0,0) + mergedImage
.size
35 image
.paste(mergedImage
, box
)