Pillow/Tests/test_psdraw.py

47 lines
1.1 KiB
Python
Raw Normal View History

from helper import unittest, PillowTestCase
2014-12-11 14:06:53 +03:00
class TestPsDraw(PillowTestCase):
def test_draw_postscript(self):
# Based on Pillow tutorial, but there is no textsize:
2014-12-11 14:06:53 +03:00
# http://pillow.readthedocs.org/en/latest/handbook/tutorial.html
# Arrange
from PIL import Image
from PIL import PSDraw
tempfile = self.tempfile('temp.ps')
2014-12-11 14:20:11 +03:00
fp = open(tempfile, "wb")
2014-12-11 14:06:53 +03:00
im = Image.open("Tests/images/hopper.ppm")
title = "hopper"
box = (1*72, 2*72, 7*72, 10*72) # in points
2014-12-11 14:06:53 +03:00
# Act
2014-12-11 14:20:11 +03:00
ps = PSDraw.PSDraw(fp)
2014-12-11 14:06:53 +03:00
ps.begin_document(title)
# draw the image (75 dpi)
ps.image(box, im, 75)
ps.rectangle(box)
# draw title
ps.setfont("Courier", 36)
ps.text((3*72, 4*72), title)
2014-12-11 14:06:53 +03:00
ps.end_document()
2014-12-11 14:20:11 +03:00
fp.close()
2014-12-11 14:06:53 +03:00
# Assert
# Check non-zero file was created
import os
self.assertTrue(os.path.isfile(tempfile))
self.assertGreater(os.path.getsize(tempfile), 0)
2014-12-11 14:06:53 +03:00
if __name__ == '__main__':
unittest.main()
# End of file