|
5 | 5 | from pilkit.lib import Image, ImageDraw, ImageColor |
6 | 6 | from pilkit.processors import (Resize, ResizeToFill, ResizeToFit, SmartCrop, |
7 | 7 | SmartResize, MakeOpaque, ColorOverlay, Convert, |
8 | | - GaussianBlur) |
| 8 | + GaussianBlur, ImageOverlay) |
9 | 9 | from pilkit.processors.resize import Thumbnail |
10 | 10 | from .utils import create_image, compare_images, get_image_file |
11 | 11 |
|
@@ -56,6 +56,32 @@ def test_coloroverlay(): |
56 | 56 | img = ColorOverlay(color, overlay_opacity=1.0).process(img) |
57 | 57 | assert img.getpixel((0,0)) == (204, 0, 0) |
58 | 58 |
|
| 59 | +def test_imageoverlay(): |
| 60 | + """ |
| 61 | + Test ImageOverlay processor |
| 62 | + """ |
| 63 | + #test with RGBA mode background image |
| 64 | + background_img_rgba = Image.open(get_image_file("reference.png")).convert("RGBA") |
| 65 | + overlay_img_rgba = Image.open(get_image_file("image_with_transparency.png")) |
| 66 | + result_1 = background_img_rgba |
| 67 | + result_1 = ImageOverlay(overlay_img_rgba, (56,156)).process(result_1) #the overlay is completely inside the background image |
| 68 | + result_1 = ImageOverlay(overlay_img_rgba, (-30,-10)).process(result_1) #the overlay top left corner is in the void |
| 69 | + result_1 = ImageOverlay(overlay_img_rgba, (199,36)).process(result_1) #the overlay bottom right corner is in the void |
| 70 | + expected_result_1 = Image.open(get_image_file("ImageOverlay_expected_result.png")).convert("RGBA") #This image have been generated with gimp |
| 71 | + assert compare_images(result_1, expected_result_1) #overlay are positioned as expected |
| 72 | + assert result_1.mode == "RGBA" #the mode of the result is the same as the original |
| 73 | + |
| 74 | + #test with RGB mode background image |
| 75 | + background_img_rgb = Image.open(get_image_file("reference.png")).convert("RGB") |
| 76 | + result_2 = background_img_rgb |
| 77 | + result_2 = ImageOverlay(overlay_img_rgba, (56,156)).process(result_2) #the overlay is completely inside the background image |
| 78 | + result_2 = ImageOverlay(overlay_img_rgba, (-30,-10)).process(result_2) #the overlay top left corner is in the void |
| 79 | + result_2 = ImageOverlay(overlay_img_rgba, (199,36)).process(result_2) #the overlay bottom right corner is in the void |
| 80 | + expected_result_2 = Image.open(get_image_file("ImageOverlay_expected_result.png")).convert("RGB") #This image have been generated with gimp |
| 81 | + assert compare_images(result_2, expected_result_2) #overlay are positioned as expected |
| 82 | + assert result_2.mode == "RGB" #the mode of the result is the same as the original |
| 83 | + |
| 84 | + |
59 | 85 | def test_convert(): |
60 | 86 | img = Image.new('RGBA', (200, 100)) |
61 | 87 |
|
|
0 commit comments