Changeset f0e64eb in OpenWorkouts-current for ow/views/user.py
- Timestamp:
- Feb 15, 2019, 11:00:35 AM (5 years ago)
- Branches:
- current, feature/docs, master
- Children:
- 0fa21cd
- Parents:
- eb20dc8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ow/views/user.py
reb20dc8 rf0e64eb 3 3 from datetime import datetime, timezone, timedelta 4 4 from decimal import Decimal 5 from io import BytesIO 5 6 6 7 from pyramid.httpexceptions import HTTPFound, HTTPNotFound … … 11 12 from pyramid_simpleform import Form, State 12 13 from pytz import common_timezones 14 from PIL import Image 13 15 14 16 from ..models.user import User … … 212 214 permission='view') 213 215 def profile_picture(context, request): 214 return Response( 215 content_type='image', 216 body_file=context.picture.open()) 216 if context.picture is None: 217 return HTTPNotFound() 218 219 size = request.GET.get('size', 0) 220 # we will need a tuple, it does not matter if both values are the same, 221 # Pillow will keep aspect ratio 222 size = (int(size), int(size)) 223 224 image = Image.open(context.picture.open()) 225 226 if size > (0, 0) and size < image.size: 227 # resize only if they are asking for smaller size, prevent 228 # someone asking for a "too big" image 229 image.thumbnail(size) 230 231 body_file = BytesIO() 232 image.save(body_file, format=image.format) 233 return Response(content_type='image', body=body_file.getvalue()) 217 234 218 235
Note: See TracChangeset
for help on using the changeset viewer.