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
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
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
jvoisin
mat2
Commits
fe885bab
Commit
fe885bab
authored
6 years ago
by
Julien (jvoisin) Voisin
Browse files
Options
Downloads
Patches
Plain Diff
Implement lightweight cleaning for jpg
parent
1040a594
No related branches found
Branches containing commit
Tags
0.12.1
Tags containing commit
No related merge requests found
Pipeline
#20025
passed
6 years ago
Stage: linting
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
libmat2/images.py
+9
-3
9 additions, 3 deletions
libmat2/images.py
tests/test_lightweigh_cleaning.py
+18
-1
18 additions, 1 deletion
tests/test_lightweigh_cleaning.py
with
27 additions
and
4 deletions
libmat2/images.py
+
9
−
3
View file @
fe885bab
...
...
@@ -6,7 +6,7 @@ import cairo
import
gi
gi
.
require_version
(
'
GdkPixbuf
'
,
'
2.0
'
)
from
gi.repository
import
GdkPixbuf
from
gi.repository
import
GdkPixbuf
,
GLib
from
.
import
exiftool
...
...
@@ -50,15 +50,21 @@ class GdkPixbufAbstractParser(exiftool.ExiftoolParser):
def
__init__
(
self
,
filename
):
super
().
__init__
(
filename
)
if
imghdr
.
what
(
filename
)
!=
self
.
_type
:
# better safe than sorry
# we can't use imghdr here because of https://bugs.python.org/issue28591
try
:
GdkPixbuf
.
Pixbuf
.
new_from_file
(
self
.
filename
)
except
GLib
.
GError
:
raise
ValueError
def
remove_all
(
self
)
->
bool
:
if
self
.
lightweight_cleaning
:
return
self
.
_lightweight_cleanup
()
_
,
extension
=
os
.
path
.
splitext
(
self
.
filename
)
pixbuf
=
GdkPixbuf
.
Pixbuf
.
new_from_file
(
self
.
filename
)
if
extension
.
lower
()
==
'
.jpg
'
:
extension
=
'
.jpeg
'
# gdk is picky
pixbuf
.
savev
(
self
.
output_filename
,
extension
[
1
:],
[],
[])
pixbuf
.
savev
(
self
.
output_filename
,
type
=
extension
[
1
:],
option_keys
=
[],
option_values
=
[])
return
True
...
...
This diff is collapsed.
Click to expand it.
tests/test_lightweigh_cleaning.py
+
18
−
1
View file @
fe885bab
...
...
@@ -4,7 +4,7 @@ import unittest
import
shutil
import
os
from
libmat2
import
pdf
,
images
from
libmat2
import
pdf
,
images
,
torrent
class
TestLightWeightCleaning
(
unittest
.
TestCase
):
def
test_pdf
(
self
):
...
...
@@ -63,3 +63,20 @@ class TestLightWeightCleaning(unittest.TestCase):
os
.
remove
(
'
./tests/data/clean.jpg
'
)
os
.
remove
(
'
./tests/data/clean.cleaned.jpg
'
)
def
test_torrent
(
self
):
shutil
.
copy
(
'
./tests/data/dirty.torrent
'
,
'
./tests/data/clean.torrent
'
)
p
=
torrent
.
TorrentParser
(
'
./tests/data/clean.torrent
'
)
meta
=
p
.
get_meta
()
self
.
assertEqual
(
meta
[
'
created by
'
],
b
'
mktorrent 1.0
'
)
p
.
lightweight_cleaning
=
True
ret
=
p
.
remove_all
()
self
.
assertTrue
(
ret
)
p
=
torrent
.
TorrentParser
(
'
./tests/data/clean.cleaned.torrent
'
)
self
.
assertEqual
(
p
.
get_meta
(),
{})
os
.
remove
(
'
./tests/data/clean.torrent
'
)
os
.
remove
(
'
./tests/data/clean.cleaned.torrent
'
)
This diff is collapsed.
Click to expand it.
jvoisin
@jvoisin
mentioned in issue
#84 (closed)
·
6 years ago
mentioned in issue
#84 (closed)
mentioned in issue #84
Toggle commit list
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