def create_avatar(self, avatar): blob_ref = Blob.create_blob_from_file(avatar, self, filename=self.username) self.set_avatar("avatar_%s" % blob_ref.name) for size, dimensions in settings.AVATAR_SIZES.iteritems(): image = images.Image(blob_ref.content) original_width, original_height = float(image.width), float(image.height) if original_width > original_height: right_x = original_height/original_width bottom_y = 1.0 else: right_x = 1.0 bottom_y = original_width/original_height image.crop(0.0, 0.0, right_x, bottom_y) width, height = dimensions image.resize(width, height) img_content = image.execute_transforms(images.JPEG) Blob.create_blob(name= "avatar_%s_%s" % (blob_ref.name, size), content=img_content, content_type="image/jpeg", user=self)
def save_with_thumbails(request, form, picture, username, sizes): logging.info("****** blob.helpers.BlobHelper.save_thumbails") if form.is_valid(): item = form.save() if picture is not None: content = picture.open().read() if content: thumbails = Blob.create_thumbails(form.cleaned_data['slug'], content, picture.content_type, username=username, sizes=sizes) item.pictures = thumbails item.picture_blob = picture item.save() return item else: request.session['form_data'] = request.POST if picture is not None: picture.delete() return None
def blob_serve(request, slug): _file = Blob.get(slug=slug) response = http.HttpResponse(content_type=_file.content_type) response.write(_file.content) return response