Commits

Matthew Turk committed 01b96b7

Adding an image primitive. Only works with PNG.

Comments (0)

Files changed (3)

examples/hello_world.py

 presentation.append(s2)
 
 if not os.path.isdir("output"): os.mkdir("output")
+
+try:
+    import matplotlib
+    matplotlib.use("Agg")
+    import pylab
+    pylab.plot([1, 2, 3, 4, 5, 6], [0, 2, 4, 5, 7, 3], '-x')
+    pylab.savefig("output/temp.png")
+    s3 = WhiteSlide([
+        primitives.ImageObject("output/temp.png", (0, 0)),
+        primitives.TextObject("Overlaid!", (100, 100))
+    ])
+    os.unlink("output/temp.png")
+    presentation.append(s3)
+except ImportError:
+    pass
+
 output = backends.PNGWriter("output/slide_%04i.png")
 output.interactor = EnterKeyPresser()
 presentation.display(output)

vanhoek/primitives/api.py

 from .text import TextObject
+from .image import ImageObject

vanhoek/primitives/image.py

+import cairo
+
+class ImageObject(object):
+    def __init__(self, filename, position):
+        self.position = position
+        self.image = cairo.ImageSurface.create_from_png(filename)
+
+    def render(self, context):
+        context.set_source_surface(self.image,
+                                   self.position[0],
+                                   self.position[1])
+        context.paint()