X-Git-Url: https://scm.cri.ensmp.fr/git/Portfolio.git/blobdiff_plain/2da869b2b46179d64c05eaac4081226fdbbbc9ff..e73353500c67453ef9663d67eaeee7dd46c358ee:/Products/Portfolio/Extensions/difference.py diff --git a/Products/Portfolio/Extensions/difference.py b/Products/Portfolio/Extensions/difference.py new file mode 100755 index 0000000..6606eff --- /dev/null +++ b/Products/Portfolio/Extensions/difference.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +############################################################ +# Copyright © 2005-2008 Benoît PIN # +# Plinn - http://plinn.org # +# # +# This program is free software; you can redistribute it # +# and/or modify it under the terms of the Creative Commons # +# "Attribution-Noncommercial 2.0 Generic" # +# http://creativecommons.org/licenses/by-nc/2.0/ # +############################################################ + +""" + + +""" +from AccessControl import Unauthorized +from PIL.Image import new as newImage, open as imgopen, composite +from PIL.ImageChops import difference +from cStringIO import StringIO + +def diffImage(self, image, image2, mask) : + iw, ih = image.size + if iw > 800 or ih > 800 : + raise Unauthorized, "You are not allowed to get an image larger than 800px" + + mask = imgopen(StringIO(str(mask))) + assert mask.mode=='L', "mask must be in L mode" + + image2 = imgopen(StringIO(str(image2))) + diffImage = difference(image, image2) + mergedImage = composite(diffImage, image, mask) + + box = (0,0) + mergedImage.size + + image.paste(mergedImage, box)