def get_image(request): img = StringIO(redis.Redis().get("cur_image")) img = Image.open(img) img = img.rotate(90) # img.save("/tmp/out.png") df = StringIO() img.save(df, "PNG") return HttpResponse(df.getvalue(), mimetype='image/png')
def fix_image_logo(src_img): global logo try: fl_img = file(src_img,'r') str_img = fl_img.read() fl_img.close() im = StringIO(str_img) im = Image.open(im) ancho, alto = im.size im.paste(logo,(ancho-110,alto-40)) if im is not None: im.save(src_img, "JPEG") except Exception as e: log.msg(str(e), level=log.ERROR) return None
def get_in_memory_image_file(): """Returns a fake image file. Faster than using file system.""" image_file = StringIO() image = PILImage.new("RGBA", size=(50, 50), color=(256, 0, 0)) image.save(image_file, 'png') name = '%s.png' % generate_random_string() image_file.name = name image_file.width = 200 image_file.height = 200 image_file._committed = False image_file.save = Mock() image_file.url = '/uploads/%s' % name image_file.__unicode__ = Mock(return_value=name) image_file.seek(0) return image_file