[Pkg-privacy-commits] [mat] 04/68: Add support for TIFF file

Sascha Steinbiss sascha at steinbiss.name
Sun Jan 3 12:32:37 UTC 2016


This is an automated email from the git hooks/post-receive script.

sascha-guest pushed a commit to branch master
in repository mat.

commit d87711e172d215198f1831cad85e7bbdae727093
Author: jvoisin <julien.voisin at dustri.org>
Date:   Mon Nov 2 18:23:57 2015 +0100

    Add support for TIFF file
---
 libmat/exiftool.py        |  39 +++++++++++++++++++++++++++------------
 libmat/strippers.py       |   2 +-
 "test/clean \303\251.tif" | Bin 0 -> 921912 bytes
 "test/dirty \303\251.tif" | Bin 0 -> 936524 bytes
 4 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/libmat/exiftool.py b/libmat/exiftool.py
index 0e1fefd..07ef06b 100644
--- a/libmat/exiftool.py
+++ b/libmat/exiftool.py
@@ -2,7 +2,6 @@
 """
 
 import subprocess
-
 import parser
 
 
@@ -29,11 +28,12 @@ class ExiftoolStripper(parser.GenericParser):
             if self.backup:
                 self.create_backup_copy()
             # Note: '-All=' must be followed by a known exiftool option.
-            subprocess.call(['exiftool', '-m', '-all=',
-                '-adobe=', '-overwrite_original', self.filename],
-                stdout=open('/dev/null'))
+            # Also, '-CommonIFD0' is needed for .tiff files
+            subprocess.call(['exiftool', '-all=', '-adobe=', '-exif:all=', '-Time:All=', '-m',
+                             '-CommonIFD0=', '-overwrite_original', self.filename],
+                            stdout=open('/dev/null'))
             return True
-        except:
+        except OSError:
             return False
 
     def is_clean(self):
@@ -48,7 +48,7 @@ class ExiftoolStripper(parser.GenericParser):
             field name : value
         """
         output = subprocess.Popen(['exiftool', self.filename],
-                stdout=subprocess.PIPE).communicate()[0]
+                                  stdout=subprocess.PIPE).communicate()[0]
         meta = {}
         for i in output.split('\n')[:-1]:  # chop last char ('\n')
             key = i.split(':')[0].strip()
@@ -61,19 +61,34 @@ class JpegStripper(ExiftoolStripper):
     """ Care about jpeg files with help
         of exiftool
     """
+
     def _set_allowed(self):
         self.allowed.update(['JFIF Version', 'Resolution Unit',
-        'X Resolution', 'Y Resolution', 'Encoding Process',
-        'Bits Per Sample', 'Color Components', 'Y Cb Cr Sub Sampling'])
+                             'X Resolution', 'Y Resolution', 'Encoding Process',
+                             'Bits Per Sample', 'Color Components', 'Y Cb Cr Sub Sampling'])
 
 
 class PngStripper(ExiftoolStripper):
     """ Care about png files with help
         of exiftool
     """
+
     def _set_allowed(self):
         self.allowed.update(['Bit Depth', 'Color Type',
-            'Compression', 'Filter', 'Interlace', 'Palette',
-            'Pixels Per Unit X',
-            'Pixels Per Unit Y', 'Pixel Units', 'Significant Bits',
-            'Background Color', 'SRGB Rendering'])
+                             'Compression', 'Filter', 'Interlace', 'Palette',
+                             'Pixels Per Unit X',
+                             'Pixels Per Unit Y', 'Pixel Units', 'Significant Bits',
+                             'Background Color', 'SRGB Rendering'])
+
+
+class TiffStripper(ExiftoolStripper):
+    """ Care about tiff files with help
+        of exiftool
+    """
+
+    def _set_allowed(self):
+        # Todo: it would be awesome to detect the Resolution Unit, and to transform it in centimeter if it's in inches.
+        self.allowed.update(['X Resolution', 'Y Resolution', 'Compression', 'Bits Per Sample',
+                             'Strip Offsets', 'Photometric Interpretation', 'Strip Byte Counts',
+                             'Resolution Unit', 'Exif Byte Order', 'Samples Per Pixel', 'Rows Per Strip',
+                             'Orientation'])
diff --git a/libmat/strippers.py b/libmat/strippers.py
index d9a8706..3aca04f 100644
--- a/libmat/strippers.py
+++ b/libmat/strippers.py
@@ -3,7 +3,6 @@
 
 import archive
 import audio
-import gi
 import images
 import logging
 import mat
@@ -67,6 +66,7 @@ try:
     import exiftool
     STRIPPERS['image/jpeg'] = exiftool.JpegStripper
     STRIPPERS['image/png'] = exiftool.PngStripper
+    STRIPPERS['image/tiff'] = exiftool.TiffStripper
 except OSError:  # if exiftool is not installed, use hachoir instead
     logging.info('Unable to find exiftool: limited images support')
     STRIPPERS['image/jpeg'] = images.JpegStripper
diff --git "a/test/clean \303\251.tif" "b/test/clean \303\251.tif"
new file mode 100644
index 0000000..697220f
Binary files /dev/null and "b/test/clean \303\251.tif" differ
diff --git "a/test/dirty \303\251.tif" "b/test/dirty \303\251.tif"
new file mode 100644
index 0000000..05b97ad
Binary files /dev/null and "b/test/dirty \303\251.tif" differ

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/mat.git



More information about the Pkg-privacy-commits mailing list