2014-12-11 14:06:53 +03:00
|
|
|
from helper import unittest, PillowTestCase, hopper
|
|
|
|
|
|
|
|
|
|
|
|
class TestPsDraw(PillowTestCase):
|
|
|
|
|
|
|
|
def test_draw_postscript(self):
|
|
|
|
|
|
|
|
# Taken from Pillow tutorial:
|
|
|
|
# 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
|
|
|
|
|
|
|
|
# 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 centered title
|
|
|
|
ps.setfont("HelveticaNarrow-Bold", 36)
|
|
|
|
w, h, b = ps.textsize(title)
|
|
|
|
ps.text((4*72-w/2, 1*72-h), title)
|
|
|
|
|
|
|
|
ps.end_document()
|
2014-12-11 14:20:11 +03:00
|
|
|
fp.close()
|
2014-12-11 14:06:53 +03:00
|
|
|
|
|
|
|
# Assert
|
|
|
|
# TODO
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|
|
|
|
|
|
|
|
# End of file
|