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
d4d6f316
Commit
d4d6f316
authored
7 years ago
by
Julien (jvoisin) Voisin
Browse files
Options
Downloads
Patches
Plain Diff
Add support for jpeg
parent
7ad9ff08
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/parsers/jpg.py
+30
-0
30 additions, 0 deletions
src/parsers/jpg.py
tests/data/dirty.jpg
+0
-0
0 additions, 0 deletions
tests/data/dirty.jpg
tests/test_libmat2.py
+22
-1
22 additions, 1 deletion
tests/test_libmat2.py
with
52 additions
and
1 deletion
src/parsers/jpg.py
0 → 100644
+
30
−
0
View file @
d4d6f316
import
subprocess
import
json
import
gi
gi
.
require_version
(
'
GdkPixbuf
'
,
'
2.0
'
)
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
'
}
def
get_meta
(
self
):
out
=
subprocess
.
check_output
([
'
exiftool
'
,
'
-json
'
,
self
.
filename
])
meta
=
json
.
loads
(
out
)[
0
]
for
key
in
self
.
meta_whitelist
:
meta
.
pop
(
key
,
None
)
return
meta
def
remove_all
(
self
):
pixbuf
=
GdkPixbuf
.
Pixbuf
.
new_from_file
(
self
.
filename
)
pixbuf
.
savev
(
self
.
output_filename
,
"
jpeg
"
,
[
"
quality
"
],
[
"
100
"
])
return
True
This diff is collapsed.
Click to expand it.
tests/data/dirty.jpg
0 → 100644
+
0
−
0
View file @
d4d6f316
136 KiB
This diff is collapsed.
Click to expand it.
tests/test_libmat2.py
+
22
−
1
View file @
d4d6f316
...
...
@@ -5,7 +5,7 @@ import shutil
import
os
from
src
import
parsers
from
src.parsers
import
pdf
,
png
from
src.parsers
import
pdf
,
png
,
jpg
class
TestGetMeta
(
unittest
.
TestCase
):
def
test_pdf
(
self
):
...
...
@@ -20,6 +20,11 @@ class TestGetMeta(unittest.TestCase):
self
.
assertEqual
(
meta
[
'
Comment
'
],
'
This is a comment, be careful!
'
)
self
.
assertEqual
(
meta
[
'
ModifyDate
'
],
"
2018:03:20 21:59:25
"
)
def
test_jpg
(
self
):
p
=
jpg
.
JPGParser
(
'
./tests/data/dirty.jpg
'
)
meta
=
p
.
get_meta
()
self
.
assertEqual
(
meta
[
'
Comment
'
],
'
Created with GIMP
'
)
class
TestCleaning
(
unittest
.
TestCase
):
def
test_pdf
(
self
):
shutil
.
copy
(
'
./tests/data/dirty.pdf
'
,
'
./tests/data/clean.pdf
'
)
...
...
@@ -51,3 +56,19 @@ class TestCleaning(unittest.TestCase):
self
.
assertEqual
(
p
.
get_meta
(),
{})
os
.
remove
(
'
./tests/data/clean.png
'
)
def
test_jpg
(
self
):
shutil
.
copy
(
'
./tests/data/dirty.jpg
'
,
'
./tests/data/clean.jpg
'
)
p
=
jpg
.
JPGParser
(
'
./tests/data/clean.jpg
'
)
meta
=
p
.
get_meta
()
self
.
assertEqual
(
meta
[
'
Comment
'
],
'
Created with GIMP
'
)
ret
=
p
.
remove_all
()
self
.
assertTrue
(
ret
)
p
=
jpg
.
JPGParser
(
'
./tests/data/clean.jpg.cleaned
'
)
self
.
assertEqual
(
p
.
get_meta
(),
{})
os
.
remove
(
'
./tests/data/clean.jpg
'
)
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