def process(image_url, processor = None, width=None, height=None, resolution=None, quality=100): conn = S3Connection(settings.AWS_ACCESS_KEY_ID, settings.AWS_SECRET_ACCESS_KEY) bucket = conn.get_bucket(settings.AWS_STORAGE_BUCKET_NAME) if image_url[0] =='/': image_url = image_url[1:] r = requests.get(image_url.replace('https', 'http')) img = Image.open(StringIO(r.content)) processor = ResizeToFit(width, height) new_img = processor.process(img) new_file = StringIO() save_image(new_img, new_file, 'JPEG') new_k = Key(bucket) parts = urlparse(image_url) img_name = os.path.splitext(os.path.basename(parts.path))[0] new_k.key = 'il/{}x{}/{}.jpeg'.format(width, height, img_name) new_k.content_type = 'image/jpeg' new_k.set_contents_from_file(new_file, policy='public-read') new_image_url = new_k.generate_url(0, query_auth=False, force_http=True) processed_image,_ = ProcessedImage.objects.update_or_create(source_image = image_url, processed_image = new_image_url) return processed_image
def test_make_gifs_opaque(): dir = os.path.dirname(__file__) path = os.path.join(dir, 'assets', 'cat.gif') gif = Image.open(path) MakeOpaque().process(gif)
def process(self, img): original = img.convert('RGBA') overlay = Image.open(self.watermark_image) img = Image.alpha_composite(original, overlay).convert('RGB') return img
def create_image(): return Image.open(get_image_file())
def test_GaussianBlur_radius_7(): img = GaussianBlur(radius=7).process(create_image()) img = img.crop((112, 112, 144, 144)) expected_img = Image.open(get_image_file("GaussianBlur_radius_7.png")) assert_true(compare_images(img, expected_img))