diff options
Diffstat (limited to 'sca-cpp/trunk/hosting/server/pictures.py')
-rw-r--r-- | sca-cpp/trunk/hosting/server/pictures.py | 20 |
1 files changed, 2 insertions, 18 deletions
diff --git a/sca-cpp/trunk/hosting/server/pictures.py b/sca-cpp/trunk/hosting/server/pictures.py index 6c5e268e0f..fa953cdc24 100644 --- a/sca-cpp/trunk/hosting/server/pictures.py +++ b/sca-cpp/trunk/hosting/server/pictures.py @@ -16,32 +16,16 @@ # under the License. # Pictures collection implementation -from StringIO import StringIO -try: - from PIL import Image -except: - Image = None -from base64 import b64encode, b64decode from urllib import urlopen from util import * from atomutil import * +from imgutil import * from sys import debug # Convert a particular user id to a picture id def pictureid(id): return ('accounts', id, 'user.picture') -# Convert image to a 50x50 PNG image -def to50x50png(url): - debug('pictures.py::to50x50png::url', url) - if Image is None: - return url - img = Image.open(StringIO(b64decode(url.split(',')[1])) if url.startswith('data:') else StringIO(urlopen(url).read())) - t = img.resize((50, 50)) - obuf = StringIO() - t.save(obuf, 'PNG') - return 'data:image/png;base64,' + b64encode(obuf.getvalue()).replace('\n', '') - # Update the user's picture def put(id, picture, user, cache): debug('pictures.py::put::id', id) @@ -57,7 +41,7 @@ def put(id, picture, user, cache): # Get image and token from input picture def image(c): img = assoc("'image", c) - return None if isNull(img) else to50x50png(cadr(img)) + return None if isNull(img) else urlto50x50jpeg(cadr(img)) def token(c): tok = assoc("'token", c) return None if isNull(tok) else cadr(tok) |