Commits

Christian Tismer committed 7169e1f

tiffany is activated. It still barfs about "TIFFReadDirectory: Warning, foo: wrong data type 3 for "Group4Options"; tag ignored.". Will look into this

  • Participants
  • Parent commits 599890d

Comments (0)

Files changed (2)

File tool/tiff_reader/__init__.py

-import os
+import os, tiffany
+from StringIO import StringIO as sio
+
 __path__[0] = os.path.realpath(__path__[0])
 __file__ = os.path.realpath(__file__)
-__path__.append(os.path.join(__path__[0], 'tiffany/from-pil'))
 
-# this is going away when tiffany is ready
-
-from .implementation import read_tiff_page
+def read_tiff_page(filename, file_or_buffer=None, pageno=1):
+    """
+    Read a file or buffer and create a new tiff buffer positioned
+    to the page wanted.
+    
+    Returns a tuple (filename, buffer)
+    
+    On Error, returns None
+    """
+    f = file_or_buffer
+    if f and not hasattr(f, 'seek'):
+        f = sio(f)
+    else:
+        f = file(filename, 'rb')
+        
+    im = tiffany.open(f)
+    im.seek(pageno)
+    newimg = sio()
+    im.save(newimg)
+    return filename, newimg.getvalue()

File tool/tiff_reader/tiffany/__init__.py

-import os
+import os, sys
 __path__[0] = os.path.realpath(__path__[0])
 __file__ = os.path.realpath(__file__)
 
+# enable global access to module 'tiffany' as long as it is not a PyPi package
+sys.path.insert(0, os.path.dirname(__path__[0]))
+
 def start_mapper():
     from import_mapper import install_mapper
     __path__.append(os.path.join(__path__[0], 'from-pil'))