yield remainder
-def rle_image(im):
+def rle_image(data):
"""
- :param im: A python PIL image.
+ :param data: A python bytearray containing a PNG.
:returns: A 2-tuple of (number of pixels, RLE-encoded pixel data)
"""
+ im = Image.open(io.BytesIO(data))
im = im.convert('RGBA')
pixels = im.getdata()
f.write(html)
f.flush()
driver.get('file://' + f.name)
- p = driver.get_screenshot_as_png()
+ data = driver.get_screenshot_as_png()
- return Image.open(io.BytesIO(p))
+ return data
finally:
driver.quit()
+from PIL import Image
import unittest
+import io
from sirius.coding import image_encoding
class ImageCase(unittest.TestCase):
def test_normal_text(self):
- image = image_encoding.html_to_png('')
+ data = image_encoding.html_to_png('')
+ image = Image.open(io.BytesIO(data))
self.assertEquals(image.size[0], 384)
def test_normal_height(self):
- image = image_encoding.html_to_png(
+ data = image_encoding.html_to_png(
'<html><body style="margin: 0px; height: 100px;"></body></html>')
+ image = Image.open(io.BytesIO(data))
self.assertEquals(image.size[1], 100)
def test_rle(self):
- image = image_encoding.html_to_png('')
- n_bytes, _ = image_encoding.rle_image(image)
+ data = image_encoding.html_to_png('')
+ image = Image.open(io.BytesIO(data))
+ n_bytes, _ = image_encoding.rle_image(data)
self.assertEquals(n_bytes, 3072)