mirror of
https://github.com/Kilian/Trimage.git
synced 2026-01-26 01:58:41 -05:00
Merge pull request #57 from Huluti/master
Fix #28 + Little changes to setup.py
This commit is contained in:
commit
f2ff0448c4
2 changed files with 12 additions and 27 deletions
23
setup.py
23
setup.py
|
|
@ -1,13 +1,8 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import sys
|
|
||||||
win=(sys.platform == "win32")
|
|
||||||
if win:
|
|
||||||
import py2exe
|
|
||||||
sys.path.append("trimage")
|
|
||||||
|
|
||||||
from distutils.core import setup
|
from distutils.core import setup
|
||||||
|
|
||||||
|
|
||||||
setup(name = "trimage",
|
setup(name = "trimage",
|
||||||
version = "1.0.5",
|
version = "1.0.5",
|
||||||
description = "Trimage image compressor - A cross-platform tool for optimizing PNG and JPG files",
|
description = "Trimage image compressor - A cross-platform tool for optimizing PNG and JPG files",
|
||||||
|
|
@ -22,18 +17,6 @@ setup(name = "trimage",
|
||||||
('share/applications', ['desktop/trimage.desktop']),
|
('share/applications', ['desktop/trimage.desktop']),
|
||||||
('share/man/man1', ['doc/trimage.1'])],
|
('share/man/man1', ['doc/trimage.1'])],
|
||||||
scripts = ["bin/trimage"],
|
scripts = ["bin/trimage"],
|
||||||
long_description = """Trimage is a cross-platform GUI and command-line interface to optimize image files via optipng, advpng and jpegoptim, depending on the filetype (currently, PNG and JPG files are supported). It was inspired by imageoptim. All image files are losslessy compressed on the highest available compression levels. Trimage gives you various input functions to fit your own workflow: A regular file dialog, dragging and dropping and various command line options.""",
|
long_description = """Trimage is a cross-platform GUI and command-line interface to optimize image files via advpng, jpegoptim, optipng and pngcrush, depending on the filetype (currently, PNG and JPG files are supported). It was inspired by imageoptim. All image files are losslessy compressed on the highest available compression levels. Trimage gives you various input functions to fit your own workflow: A regular file dialog, dragging and dropping and various command line options.""",
|
||||||
requires = ["PyQt5"],
|
requires = ["PyQt5"]
|
||||||
|
|
||||||
#for py2exe
|
|
||||||
windows=[r'trimage\trimage.py'],
|
|
||||||
zipfile=None,
|
|
||||||
options={"py2exe":{
|
|
||||||
"optimize":2,
|
|
||||||
"compressed":1,
|
|
||||||
"bundle_files":1,
|
|
||||||
"includes":["sip",],
|
|
||||||
"excludes":['email'],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -305,7 +305,7 @@ class ImageRow:
|
||||||
"""Build the information visible in the table image row."""
|
"""Build the information visible in the table image row."""
|
||||||
self.image = image
|
self.image = image
|
||||||
d = {
|
d = {
|
||||||
'shortname': lambda i: self.statusStr() % i.shortname,
|
'filename_w_ext': lambda i: self.statusStr() % i.filename_w_ext,
|
||||||
'oldfilesizestr': lambda i: human_readable_size(i.oldfilesize)
|
'oldfilesizestr': lambda i: human_readable_size(i.oldfilesize)
|
||||||
if i.compressed else "",
|
if i.compressed else "",
|
||||||
'newfilesizestr': lambda i: human_readable_size(i.newfilesize)
|
'newfilesizestr': lambda i: human_readable_size(i.newfilesize)
|
||||||
|
|
@ -316,7 +316,7 @@ class ImageRow:
|
||||||
'icon': lambda i: i.icon if i.compressed else waitingIcon,
|
'icon': lambda i: i.icon if i.compressed else waitingIcon,
|
||||||
'fullpath': lambda i: i.fullpath, #only used by cli
|
'fullpath': lambda i: i.fullpath, #only used by cli
|
||||||
}
|
}
|
||||||
names = ['shortname', 'oldfilesizestr', 'newfilesizestr',
|
names = ['filename_w_ext', 'oldfilesizestr', 'newfilesizestr',
|
||||||
'ratiostr', 'icon']
|
'ratiostr', 'icon']
|
||||||
for i, n in enumerate(names):
|
for i, n in enumerate(names):
|
||||||
d[i] = d[n]
|
d[i] = d[n]
|
||||||
|
|
@ -346,13 +346,14 @@ class Image:
|
||||||
self.valid = False
|
self.valid = False
|
||||||
self.reset()
|
self.reset()
|
||||||
self.fullpath = fullpath
|
self.fullpath = fullpath
|
||||||
|
self.filename_w_ext = path.basename(self.fullpath)
|
||||||
|
self.filename, self.filetype = path.splitext(self.filename_w_ext)
|
||||||
if path.isfile(self.fullpath) and access(self.fullpath, W_OK):
|
if path.isfile(self.fullpath) and access(self.fullpath, W_OK):
|
||||||
self.filetype = path.splitext(self.fullpath)[1][1:].lower()
|
self.filetype = self.filetype[1:].lower()
|
||||||
if self.filetype == "jpg":
|
if self.filetype == "jpg":
|
||||||
self.filetype = "jpeg"
|
self.filetype = "jpeg"
|
||||||
if self.filetype in ["jpeg", "png"]:
|
if self.filetype in ["jpeg", "png"]:
|
||||||
oldfile = QFileInfo(self.fullpath)
|
oldfile = QFileInfo(self.fullpath)
|
||||||
self.shortname = oldfile.fileName()
|
|
||||||
self.oldfilesize = oldfile.size()
|
self.oldfilesize = oldfile.size()
|
||||||
self.icon = QIcon(self.fullpath)
|
self.icon = QIcon(self.fullpath)
|
||||||
self.valid = True
|
self.valid = True
|
||||||
|
|
@ -376,7 +377,8 @@ class Image:
|
||||||
"png": "optipng" + exe + " -force -o7 '%(file)s'&&advpng" + exe + " -z4 '%(file)s' && pngcrush -rem gAMA -rem alla -rem cHRM -rem iCCP -rem sRGB -rem time '%(file)s' '%(file)s.bak' && mv '%(file)s.bak' '%(file)s'"
|
"png": "optipng" + exe + " -force -o7 '%(file)s'&&advpng" + exe + " -z4 '%(file)s' && pngcrush -rem gAMA -rem alla -rem cHRM -rem iCCP -rem sRGB -rem time '%(file)s' '%(file)s.bak' && mv '%(file)s.bak' '%(file)s'"
|
||||||
}
|
}
|
||||||
# create a backup file
|
# create a backup file
|
||||||
copy(self.fullpath, self.fullpath + '~')
|
backupfullpath = '/tmp/' + self.filename_w_ext
|
||||||
|
copy(self.fullpath, backupfullpath)
|
||||||
try:
|
try:
|
||||||
retcode = call(runString[self.filetype] % {"file": self.fullpath},
|
retcode = call(runString[self.filetype] % {"file": self.fullpath},
|
||||||
shell=True, stdout=PIPE)
|
shell=True, stdout=PIPE)
|
||||||
|
|
@ -388,11 +390,11 @@ class Image:
|
||||||
|
|
||||||
# checks the new file and copy the backup
|
# checks the new file and copy the backup
|
||||||
if self.newfilesize >= self.oldfilesize:
|
if self.newfilesize >= self.oldfilesize:
|
||||||
copy(self.fullpath + '~', self.fullpath)
|
copy(backupfullpath, self.fullpath)
|
||||||
self.newfilesize = self.oldfilesize
|
self.newfilesize = self.oldfilesize
|
||||||
|
|
||||||
# removes the backup file
|
# removes the backup file
|
||||||
remove(self.fullpath + '~')
|
remove(backupfullpath)
|
||||||
else:
|
else:
|
||||||
self.failed = True
|
self.failed = True
|
||||||
self.compressing = False
|
self.compressing = False
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue