From c791bcd8d55f612053e35109ba12a8ee01e8c5e9 Mon Sep 17 00:00:00 2001
From: Romain Courteaud <romain@nexedi.com>
Date: Thu, 30 Jun 2011 10:04:20 +0200
Subject: [PATCH] Generate by default indexed 8bpp tiff image. This is the
 expected parameter to allow tesseract convertion.

---
 .../PortalTransforms/libtransforms/imagemagick_transform.py    | 3 +++
 product/PortalTransforms/transforms/image_to_tiff.py           | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/product/PortalTransforms/libtransforms/imagemagick_transform.py b/product/PortalTransforms/libtransforms/imagemagick_transform.py
index c5a6820d31..8a300986ef 100644
--- a/product/PortalTransforms/libtransforms/imagemagick_transform.py
+++ b/product/PortalTransforms/libtransforms/imagemagick_transform.py
@@ -22,6 +22,9 @@ class ImageMagickTransforms:
             parameter_list.extend(['-resize', '%sx%s!' % (newwidth, newheight)])
         elif newwidth or newheight:
             parameter_list.extend(['-resize', '%sx%s' % (newwidth, newheight)])
+        depth = kwargs.get('depth','')
+        if depth:
+            parameter_list.extend(['-depth', '%s' % depth, '-type', 'Palette'])
         parameter_list.append('%s:-' % self.format)
         process = subprocess.Popen(parameter_list,
                                    stdin=subprocess.PIPE,
diff --git a/product/PortalTransforms/transforms/image_to_tiff.py b/product/PortalTransforms/transforms/image_to_tiff.py
index 29418cbbab..980cdf573f 100644
--- a/product/PortalTransforms/transforms/image_to_tiff.py
+++ b/product/PortalTransforms/transforms/image_to_tiff.py
@@ -6,6 +6,9 @@ class image_to_tiff(ImageMagickTransforms):
     output   = 'image/tiff'
     format  = 'tiff'
 
+    def convert(self, orig, data, depth=8, **kwargs):
+        return ImageMagickTransforms.convert(self, orig, data, depth=depth, **kwargs)
+
 
 def register():
     return image_to_tiff()
-- 
2.30.9