show old filesize next to new filesize, implement jpg optimisation

This commit is contained in:
Kilian Valkhof 2010-02-02 14:19:10 +01:00
parent b02d6e0aa6
commit 3ec1938b3e
5 changed files with 15 additions and 13 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 603 B

After

Width:  |  Height:  |  Size: 554 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 601 B

After

Width:  |  Height:  |  Size: 678 B

Before After
Before After

7
todo
View file

@ -12,18 +12,17 @@
- jpegoptim * - jpegoptim *
- libjpeg/jpegtran * - libjpeg/jpegtran *
gif: gif:
- optipng * - optipng * no
- gifsicle * (maybe) - gifsicle * (maybe)
* = available in ubuntu * = available in ubuntu
trimage: simple gui for: trimage: simple gui for:
optipng for png and gif, jpegoptim for jpeg. both are available in ubuntu as dependencies (our primary platform) optipng for png and gif, jpegoptim for jpeg. both are available in ubuntu as dependencies (our primary platform)
^ no gif. optipng optimized gif by converting to png
========================================== ==========================================
todo app wise todo app wise
- implement jpegoptim - implement something for gifs (or not)
- implement something for gifs
- implement drag and drop on table - implement drag and drop on table
- clean up code, make it PEP-8 - clean up code, make it PEP-8
- figure out what to do with: - figure out what to do with:

View file

@ -23,9 +23,11 @@ class StartQT4(QMainWindow):
QObject.connect(self.quit_shortcut, SIGNAL("activated()"), qApp, SLOT('quit()')) QObject.connect(self.quit_shortcut, SIGNAL("activated()"), qApp, SLOT('quit()'))
QObject.connect(self.ui.processedfiles, SIGNAL("dragEnterEvent()"), self.file_drop) QObject.connect(self.ui.processedfiles, SIGNAL("dragEnterEvent()"), self.file_drop)
def file_drop(self): def file_drop(self):
print "booya" print "booya"
def file_dialog(self): def file_dialog(self):
fd = QFileDialog(self) fd = QFileDialog(self)
images = fd.getOpenFileNames(self, images = fd.getOpenFileNames(self,
@ -41,9 +43,9 @@ class StartQT4(QMainWindow):
def recompress_files(self): def recompress_files(self):
newimage = self.imagelist imagelistcopy = self.imagelist
self.imagelist = [] self.imagelist = []
for image in newimage: for image in imagelistcopy:
self.compress_file(image[-1]) self.compress_file(image[-1])
@ -52,20 +54,21 @@ class StartQT4(QMainWindow):
oldfile = QFileInfo(filename); oldfile = QFileInfo(filename);
name = oldfile.fileName() name = oldfile.fileName()
oldfilesize = oldfile.size() oldfilesize = oldfile.size()
oldfilesizestr = size(oldfilesize, system=alternative)
if name.endsWith("jpg"): if name.endsWith("jpg"):
print "run jpegoptim" runstr = 'jpegoptim --strip-all -f "' + str(filename) + '"'
runfile = system('ls') runfile = system(runstr)
elif name.endsWith("png"): elif name.endsWith("png"):
runstr = 'optipng -force "' + str(filename) + '"' #runstr = 'optipng -force -o7 "' + str(filename) + '"; advpng -z4 "' + str(filename) + '"' ## don't do advpng yet
runstr = 'optipng -force -o7 "' + str(filename) + '"'
runfile = system(runstr) runfile = system(runstr)
else: else:
print "run something for gif" print "run something for gif"
runfile = system('ls') runfile = system('ls')
if runfile == 0: if runfile == 0:
newfile = QFile(filename) newfile = QFile(filename)
newfilesize = newfile.size() newfilesize = newfile.size()
@ -74,7 +77,7 @@ class StartQT4(QMainWindow):
ratio = 100 - (float(newfilesize) / float(oldfilesize) * 100) ratio = 100 - (float(newfilesize) / float(oldfilesize) * 100)
ratiostr = "%.1f%%" % ratio ratiostr = "%.1f%%" % ratio
self.imagelist.append((name, newfilesizestr, ratiostr, filename)) self.imagelist.append((name, oldfilesizestr, newfilesizestr, ratiostr, filename))
self.update_table() self.update_table()
else: else:
@ -87,7 +90,7 @@ class StartQT4(QMainWindow):
# set table model # set table model
tmodel = tri_table_model(self, tmodel = tri_table_model(self,
self.imagelist, self.imagelist,
[' Filename ', ' Size ', ' Compressed ']) ['Filename', 'Old Size', 'New Size', 'Compressed'])
tview.setModel(tmodel) tview.setModel(tmodel)
# set minimum size of table # set minimum size of table
@ -102,7 +105,7 @@ class StartQT4(QMainWindow):
nrows = len(self.imagelist) nrows = len(self.imagelist)
for row in range(nrows): for row in range(nrows):
tview.setRowHeight(row, 25) tview.setRowHeight(row, 25)
tview.setColumnWidth(0,400) tview.setColumnWidth(0,300)
tview.setDragDropMode(QAbstractItemView.DropOnly) tview.setDragDropMode(QAbstractItemView.DropOnly)
tview.setAcceptDrops(True) tview.setAcceptDrops(True)
self.enable_recompress() self.enable_recompress()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2 KiB

After

Width:  |  Height:  |  Size: 2 KiB

Before After
Before After