Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
mat2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tails
mat2
Commits
2d7c703c
Commit
2d7c703c
authored
6 years ago
by
Julien (jvoisin) Voisin
Browse files
Options
Downloads
Patches
Plain Diff
Add support for .tiff files
parent
c186fc42
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/images_pixbuf.py
+30
-11
30 additions, 11 deletions
src/images_pixbuf.py
tests/data/dirty.tiff
+0
-0
0 additions, 0 deletions
tests/data/dirty.tiff
tests/test_libmat2.py
+26
-4
26 additions, 4 deletions
tests/test_libmat2.py
with
56 additions
and
15 deletions
src/
jpg
.py
→
src/
images_pixbuf
.py
+
30
−
11
View file @
2d7c703c
import
subprocess
import
json
import
os
import
gi
gi
.
require_version
(
'
GdkPixbuf
'
,
'
2.0
'
)
...
...
@@ -7,16 +8,7 @@ from gi.repository import GdkPixbuf
from
.
import
abstract
class
JPGParser
(
abstract
.
AbstractParser
):
mimetypes
=
{
'
image/jpg
'
,
}
meta_whitelist
=
{
'
SourceFile
'
,
'
ExifToolVersion
'
,
'
FileName
'
,
'
Directory
'
,
'
FileSize
'
,
'
FileModifyDate
'
,
'
FileAccessDate
'
,
"
FileInodeChangeDate
"
,
'
FilePermissions
'
,
'
FileType
'
,
'
FileTypeExtension
'
,
'
MIMEType
'
,
'
ImageWidth
'
,
'
ImageSize
'
,
'
BitsPerSample
'
,
'
ColorComponents
'
,
'
EncodingProcess
'
,
'
JFIFVersion
'
,
'
ResolutionUnit
'
,
'
XResolution
'
,
'
YCbCrSubSampling
'
,
'
YResolution
'
,
'
Megapixels
'
,
'
ImageHeight
'
}
class
GdkPixbufAbstractParser
(
abstract
.
AbstractParser
):
def
get_meta
(
self
):
out
=
subprocess
.
check_output
([
'
exiftool
'
,
'
-json
'
,
self
.
filename
])
meta
=
json
.
loads
(
out
.
decode
(
'
utf-8
'
))[
0
]
...
...
@@ -25,6 +17,33 @@ class JPGParser(abstract.AbstractParser):
return
meta
def
remove_all
(
self
):
_
,
extension
=
os
.
path
.
splitext
(
self
.
filename
)
pixbuf
=
GdkPixbuf
.
Pixbuf
.
new_from_file
(
self
.
filename
)
pixbuf
.
savev
(
self
.
output_filename
,
"
jpeg
"
,
[
"
quality
"
],
[
"
100
"
])
if
extension
==
'
.jpg
'
:
extension
=
'
.jpeg
'
pixbuf
.
savev
(
self
.
output_filename
,
extension
[
1
:],
[
"
quality
"
],
[
"
100
"
])
return
True
class
JPGParser
(
GdkPixbufAbstractParser
):
mimetypes
=
{
'
image/jpg
'
}
meta_whitelist
=
{
'
SourceFile
'
,
'
ExifToolVersion
'
,
'
FileName
'
,
'
Directory
'
,
'
FileSize
'
,
'
FileModifyDate
'
,
'
FileAccessDate
'
,
"
FileInodeChangeDate
"
,
'
FilePermissions
'
,
'
FileType
'
,
'
FileTypeExtension
'
,
'
MIMEType
'
,
'
ImageWidth
'
,
'
ImageSize
'
,
'
BitsPerSample
'
,
'
ColorComponents
'
,
'
EncodingProcess
'
,
'
JFIFVersion
'
,
'
ResolutionUnit
'
,
'
XResolution
'
,
'
YCbCrSubSampling
'
,
'
YResolution
'
,
'
Megapixels
'
,
'
ImageHeight
'
}
class
TiffParser
(
GdkPixbufAbstractParser
):
mimetypes
=
{
'
image/tiff
'
}
meta_whitelist
=
{
'
Compression
'
,
'
ExifByteOrder
'
,
'
ExtraSamples
'
,
'
FillOrder
'
,
'
PhotometricInterpretation
'
,
'
PlanarConfiguration
'
,
'
RowsPerStrip
'
,
'
SamplesPerPixel
'
,
'
StripByteCounts
'
,
'
StripOffsets
'
,
'
BitsPerSample
'
,
'
Directory
'
,
'
ExifToolVersion
'
,
'
FileAccessDate
'
,
'
FileInodeChangeDate
'
,
'
FileModifyDate
'
,
'
FileName
'
,
'
FilePermissions
'
,
'
FileSize
'
,
'
FileType
'
,
'
FileTypeExtension
'
,
'
ImageHeight
'
,
'
ImageSize
'
,
'
ImageWidth
'
,
'
MIMEType
'
,
'
Megapixels
'
,
'
SourceFile
'
}
This diff is collapsed.
Click to expand it.
tests/data/dirty.tiff
0 → 100644
+
0
−
0
View file @
2d7c703c
915 KiB
This diff is collapsed.
Click to expand it.
tests/test_libmat2.py
+
26
−
4
View file @
2d7c703c
...
...
@@ -6,7 +6,7 @@ import os
import
zipfile
import
tempfile
from
src
import
pdf
,
png
,
jpg
,
audio
,
office
,
libreoffice
,
parser_factory
from
src
import
pdf
,
png
,
images_pixbuf
,
audio
,
office
,
libreoffice
,
parser_factory
class
TestGetMeta
(
unittest
.
TestCase
):
def
test_pdf
(
self
):
...
...
@@ -22,10 +22,17 @@ class TestGetMeta(unittest.TestCase):
self
.
assertEqual
(
meta
[
'
ModifyDate
'
],
"
2018:03:20 21:59:25
"
)
def
test_jpg
(
self
):
p
=
jpg
.
JPGParser
(
'
./tests/data/dirty.jpg
'
)
p
=
images_pixbuf
.
JPGParser
(
'
./tests/data/dirty.jpg
'
)
meta
=
p
.
get_meta
()
self
.
assertEqual
(
meta
[
'
Comment
'
],
'
Created with GIMP
'
)
def
test_tiff
(
self
):
p
=
images_pixbuf
.
JPGParser
(
'
./tests/data/dirty.tiff
'
)
meta
=
p
.
get_meta
()
self
.
assertEqual
(
meta
[
'
Make
'
],
'
OLYMPUS IMAGING CORP.
'
)
self
.
assertEqual
(
meta
[
'
Model
'
],
'
C7070WZ
'
)
self
.
assertEqual
(
meta
[
'
ModifyDate
'
],
'
2005:12:26 17:09:35
'
)
def
test_mp3
(
self
):
p
=
audio
.
MP3Parser
(
'
./tests/data/dirty.mp3
'
)
meta
=
p
.
get_meta
()
...
...
@@ -152,7 +159,7 @@ class TestCleaning(unittest.TestCase):
def
test_jpg
(
self
):
shutil
.
copy
(
'
./tests/data/dirty.jpg
'
,
'
./tests/data/clean.jpg
'
)
p
=
jpg
.
JPGParser
(
'
./tests/data/clean.jpg
'
)
p
=
images_pixbuf
.
JPGParser
(
'
./tests/data/clean.jpg
'
)
meta
=
p
.
get_meta
()
self
.
assertEqual
(
meta
[
'
Comment
'
],
'
Created with GIMP
'
)
...
...
@@ -160,7 +167,7 @@ class TestCleaning(unittest.TestCase):
ret
=
p
.
remove_all
()
self
.
assertTrue
(
ret
)
p
=
jpg
.
JPGParser
(
'
./tests/data/clean.jpg.cleaned
'
)
p
=
images_pixbuf
.
JPGParser
(
'
./tests/data/clean.jpg.cleaned
'
)
self
.
assertEqual
(
p
.
get_meta
(),
{})
os
.
remove
(
'
./tests/data/clean.jpg
'
)
...
...
@@ -240,3 +247,18 @@ class TestCleaning(unittest.TestCase):
self
.
assertEqual
(
p
.
get_meta
(),
{})
os
.
remove
(
'
./tests/data/clean.odt
'
)
def
test_tiff
(
self
):
shutil
.
copy
(
'
./tests/data/dirty.tiff
'
,
'
./tests/data/clean.tiff
'
)
p
=
images_pixbuf
.
TiffParser
(
'
./tests/data/clean.tiff
'
)
meta
=
p
.
get_meta
()
self
.
assertEqual
(
meta
[
'
Model
'
],
'
C7070WZ
'
)
ret
=
p
.
remove_all
()
self
.
assertTrue
(
ret
)
p
=
images_pixbuf
.
TiffParser
(
'
./tests/data/clean.tiff.cleaned
'
)
self
.
assertEqual
(
p
.
get_meta
(),
{})
os
.
remove
(
'
./tests/data/clean.tiff
'
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment