2014-07-07 21:03:50 +04:00
|
|
|
from helper import unittest, PillowTestCase, lena
|
2012-10-16 00:26:38 +04:00
|
|
|
|
|
|
|
from PIL import Image
|
2014-01-23 08:40:37 +04:00
|
|
|
import io
|
2012-10-16 00:26:38 +04:00
|
|
|
|
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
class TestFileBmp(PillowTestCase):
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
def roundtrip(self, im):
|
|
|
|
outfile = self.tempfile("temp.bmp")
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
im.save(outfile, 'BMP')
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
reloaded = Image.open(outfile)
|
|
|
|
reloaded.load()
|
|
|
|
self.assertEqual(im.mode, reloaded.mode)
|
|
|
|
self.assertEqual(im.size, reloaded.size)
|
|
|
|
self.assertEqual(reloaded.format, "BMP")
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
def test_sanity(self):
|
|
|
|
self.roundtrip(lena())
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
self.roundtrip(lena("1"))
|
|
|
|
self.roundtrip(lena("L"))
|
|
|
|
self.roundtrip(lena("P"))
|
|
|
|
self.roundtrip(lena("RGB"))
|
2014-01-23 08:40:37 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
def test_save_to_bytes(self):
|
|
|
|
output = io.BytesIO()
|
|
|
|
im = lena()
|
|
|
|
im.save(output, "BMP")
|
|
|
|
|
|
|
|
output.seek(0)
|
|
|
|
reloaded = Image.open(output)
|
|
|
|
|
|
|
|
self.assertEqual(im.mode, reloaded.mode)
|
|
|
|
self.assertEqual(im.size, reloaded.size)
|
|
|
|
self.assertEqual(reloaded.format, "BMP")
|
|
|
|
|
2014-06-29 01:22:52 +04:00
|
|
|
def test_dpi(self):
|
|
|
|
dpi = (72, 72)
|
|
|
|
|
|
|
|
output = io.BytesIO()
|
|
|
|
im = lena()
|
|
|
|
im.save(output, "BMP", dpi=dpi)
|
|
|
|
|
|
|
|
output.seek(0)
|
|
|
|
reloaded = Image.open(output)
|
|
|
|
|
|
|
|
self.assertEqual(reloaded.info["dpi"], dpi)
|
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|
|
|
|
|
|
|
|
# End of file
|