def test_non_indexed_interlaced(self): img = Image.open_from_path(_get_filepath('black-white-non-indexed-interlaced-adam7.png')) print(img.pixels) self.assertEqual(img.get_color(0, 0), BLACK) self.assertEqual(img.get_color(1, 1), BLACK) self.assertEqual(img.get_color(0, 1), WHITE) self.assertEqual(img.get_color(1, 0), WHITE)
def test_decode(self): img = Image.open_from_path(_get_filepath('black-white-100.jpg')) self.assertEqual(img.get_color(0, 0), Black) # TODO: Is this correct? Is this just JPEG being JPEG or is the decoder # buggy? 1/1 SHOULD be BLACK but it's 8 8 8. self.assertEqual(img.get_color(1, 1), ALMOST_BLACK) self.assertEqual(img.get_color(0, 1), White) self.assertEqual(img.get_color(1, 0), White)
def test_decode(self): img = Image.open_from_path( get_test_file(__file__, 'black-white-100.jpg')) self.assertImage( img, [ [Black, White], [White, ALMOST_BLACK] # no clue why this is "almost" black ], False)
def lambda_handler(event, context): print("Received event: " + json.dumps(event, indent=2)) srcBucket = event.Records[0].s3.bucket.name srcKey = event.Records[0].s3.object.key dstBucket = srcBucket dstKey = 'thumbs/' + srcKey bucket = s3.Bucket(srcBucket) imageObject = bucket.Object(srcKey) metadata = image.metadata if 'width' in metadata: max_width = metadata['width'] else: max_width = DEFAULT_MAX_WIDTH if 'height' in metadata: max_height = metadata['height'] else: max_height = DEFAULT_MAX_HEIGHT scalingFactor = min(max_width / size.width, max_height / size.height) width = scalingFactor * size.width height = scalingFactor * size.height random_file_name = uuid.uuid4() + srcKey image_path = '/tmp/' + random_file_name thumbnail_path = '/tmp/resized-' + random_file_name s3.download_file(srcBucket, srcKey, image_path) resize_image(image_path, thumbnail_path) with Image.open_from_path(image_path) as image: image.img.resize(width, height) image.save(thumbnail_path) s3.upload_file(thumbnail_path, dstBucket, dstKey)
from pymaging import Image Image.open_from_path('testimage.png').resize(160, 240).save_to_path('resized_benchimage.png')
from timeit import default_timer as time import sys from pymaging import Image start_time = time() elapsed = 0 for i in xrange(0, 1000): Image.open_from_path('testimage.png').flip_left_right().save_to_path('benchimage.png') elapsed = time() - start_time if elapsed > 1.0: break trials = i + 1 print "{trials:d} iterations in {elapsed:0.2f} seconds ({average:0.2f}s/call)".format(trials=trials, elapsed=elapsed, average=elapsed / trials)
def test_with_transparency(self): img = Image.open_from_path(_get_filepath('black-white-with-transparency.png')) self.assertEqual(img.get_color(0, 0), BLACK) self.assertEqual(img.get_color(1, 0), WHITE) self.assertEqual(img.get_color(1, 1), BLACK.get_for_brightness(0.5)) self.assertEqual(img.get_color(0, 1), WHITE.get_for_brightness(0.5))
def test_non_indexed(self): img = Image.open_from_path(_get_filepath('black-white-non-indexed.png')) self.assertEqual(img.get_color(0, 0), BLACK) self.assertEqual(img.get_color(1, 1), BLACK) self.assertEqual(img.get_color(0, 1), WHITE) self.assertEqual(img.get_color(1, 0), WHITE)
def test_decode(self): img = Image.open_from_path(get_test_file(__file__, "black-white-100.jpg")) self.assertImage(img, [[Black, White], [White, ALMOST_BLACK]], False) # no clue why this is "almost" black