bugfix : copier/coller hasardeux.
[Portfolio.git] / Extensions / difference.py
1 # -*- coding: utf-8 -*-
2 ############################################################
3 # Copyright © 2005-2008 Benoît PIN <benoit.pin@ensmp.fr> #
4 # Plinn - http://plinn.org #
5 # #
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 ############################################################
11
12 """
13
14
15 """
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
20
21 def diffImage(self, image, image2, mask) :
22 iw, ih = image.size
23 if iw > 800 or ih > 800 :
24 raise Unauthorized, "You are not allowed to get an image larger than 800px"
25
26 mask = imgopen(StringIO(str(mask)))
27 assert mask.mode=='L', "mask must be in L mode"
28
29 image2 = imgopen(StringIO(str(image2)))
30 diffImage = difference(image, image2)
31 mergedImage = composite(diffImage, image, mask)
32
33 box = (0,0) + mergedImage.size
34
35 image.paste(mergedImage, box)