Compare commits

..

No commits in common. "master" and "1.0.5" have entirely different histories.

37 changed files with 759 additions and 571 deletions

117
.gitignore vendored
View file

@ -1,116 +1,5 @@
# Byte-compiled / optimized / DLL files *.pyc
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST MANIFEST
dist/
build/
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/

View file

@ -1,3 +1,4 @@
include COPYING MANIFEST MANIFEST.in README.md bin/trimage include COPYING MANIFEST MANIFEST.in README trimage
recursive-include desktop *.svg *.desktop recursive-include desktop *.svg *.desktop
recursive-include trimage/ *.py *.png recursive-include src/ *.py *.png

15
README Normal file
View file

@ -0,0 +1,15 @@
Trimage image compressor
A cross-platform tool for optimizing PNG and JPG files.
Trimage is a cross-platform GUI and command-line interface to optimize image
files via "optipng":http://optipng.sourceforge.net/,
"advpng":http://advancemame.sourceforge.net/comp-readme.html and
"jpegoptim":http://www.kokkonen.net/tjko/projects.html, depending on the
filetype (currently, PNG and JPG files are supported). It was inspired by
"imageoptim":http://imageoptim.pornel.net/. All image files are losslessly
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.
Visit "Trimage.org":http://trimage.org for more information

View file

@ -1,44 +0,0 @@
### Made by [@kilianvalkhof](https://twitter.com/kilianvalkhof)
#### Other projects:
- 💻 [Polypane](https://polypane.app) - Develop responsive websites and apps twice as fast on multiple screens at once
- 🖌️ [Superposition](https://superposition.design) - Kickstart your design system by extracting design tokens from your website
- 🗒️ [FromScratch](https://fromscratch.rocks) - A smart but simple autosaving scratchpad
---
# Trimage image compressor
A cross-platform tool for optimizing PNG and JPG files.
Trimage is a cross-platform GUI and command-line interface to optimize image files via [advpng](http://advancemame.sourceforge.net/comp-readme.html), [jpegoptim](http://www.kokkonen.net/tjko/projects.html), [optipng](http://optipng.sourceforge.net) and [pngcrush](https://pmt.sourceforge.io/pngcrush) depending on the
filetype (currently, PNG and JPG files are supported).
It was inspired by
[imageoptim](http://imageoptim.pornel.net).
All image files are losslessly
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.
## Installation instructions
Visit [Trimage.org](http://trimage.org) to install Trimage as a package.
## Building instructions
### Prerequisites
- PyQt5
- advpng
- jpegoptim
- optipng
- pngcrush
### Build from source
Build and install by running:
python setup.py build
sudo python setup.py install

17
TODO.md
View file

@ -1,17 +0,0 @@
# Todo
- general refactoring
- sys.exit(1) for errors -- how to handle? Not good to simply sys.exit() from any random part of code (can leave things in a mess)
- consider context managers for handling compression, so as to keep operations atomic and/or rollback-able
- add a recursive option on the command-line for use with -d
- make -f accept a list of files
- make the current verbose be "normal", and make -verbose print the commandline app prints as well
- find a way to specify the version once for everywhere
- notification area drag/drop widget -> probably need gtk for gnome
- figure out how to make mac and win versions (someone else :) <- via gui2exe
- animate compressing.gif
- allow selection/deletion of rows from table (and subsequently the imagelist)
- punypng api? http://www.gracepointafterfive.com/punypng/api
- imagemagick/graphicsmagick?
- always on top option
- intelligently recompress, i.e. go through the list of files, recompress each until no more gains are seen (and a sensible number-of-tries limit isn't exceeded), and flag that file as fully-optimised. Repeat for each file in the list, until all are done. Saves pointlessly trying to optimise files. Consider the case of a directory of 100 files, already optimised once. Recompressing maximally compresses 90. Recompressing again would currently try to recompress all 100, when only 10 would be worthy of trying to compress further

9
debian/changelog vendored
View file

@ -1,11 +1,3 @@
trimage (1.0.6-0ubuntu1) bionic; urgency=low
* Migrate to python 3 and python-qt 5
* fix bug with hanging thread
* remove hurry.filesize package
-- Kilian Valkhof <kilian@kilianvalkhof.com> Tue, 12 Mar 2019 11:54:00 +0200
trimage (1.0.5-0ubuntu1) jaunty; urgency=low trimage (1.0.5-0ubuntu1) jaunty; urgency=low
* prevent images from becoming larger after recompression * prevent images from becoming larger after recompression
@ -78,3 +70,4 @@ trimage (1.0.0b-0ubuntu1) jaunty; urgency=low
* Trimage image compressor * Trimage image compressor
-- Kilian Valkhof <help@trimage.org> Tue, 23 Mar 2010 20:18:17 +0100 -- Kilian Valkhof <help@trimage.org> Tue, 23 Mar 2010 20:18:17 +0100

2
debian/compat vendored
View file

@ -1 +1 @@
11 7

9
debian/control vendored
View file

@ -2,13 +2,15 @@ Source: trimage
Section: graphics Section: graphics
Priority: optional Priority: optional
Maintainer: Kilian Valkhof <kilian@kilianvalkhof.com> Maintainer: Kilian Valkhof <kilian@kilianvalkhof.com>
Build-Depends: debhelper (>=7), python3 Build-Depends: debhelper (>=7), python-support (>=0.8.7), python
Standards-Version: 4.3.0 XS-Python-Version: >=2.6
Standards-Version: 3.9.1
Homepage: http://trimage.org Homepage: http://trimage.org
Package: trimage Package: trimage
Architecture: all Architecture: all
Depends: ${misc:Depends}, ${python:Depends}, python-pyqt5 (>=5.7), optipng (>=0.6.2.1), advancecomp (>=1.15), jpegoptim (>=1.2.2), pngcrush (>=1.6.7) Depends: ${misc:Depends}, ${python:Depends}, python-qt4 (>=4.4), optipng (>=0.6.2.1), advancecomp (>=1.15), jpegoptim (>=1.2.2), pngcrush (>=1.6.7)
XB-Python-Version: ${python:Versions}
Description: GUI and command-line interface to optimize image files Description: GUI and command-line interface to optimize image files
Trimage is a cross-platform GUI and command-line interface to optimize image Trimage is a cross-platform GUI and command-line interface to optimize image
files via optipng, advpng, pngcrush and jpegoptim, depending on the filetype files via optipng, advpng, pngcrush and jpegoptim, depending on the filetype
@ -16,3 +18,4 @@ Description: GUI and command-line interface to optimize image files
compressed on the highest available compression levels. Trimage gives you compressed on the highest available compression levels. Trimage gives you
various input functions to fit your own workflow: A regular file dialog, various input functions to fit your own workflow: A regular file dialog,
dragging and dropping and various command line options. dragging and dropping and various command line options.

44
debian/copyright vendored
View file

@ -39,6 +39,49 @@ The Debian packaging is:
and is licensed under the MIT license, see above. and is licensed under the MIT license, see above.
hurry.filesize is:
Copyright (C) Martijn Faassen, Startifact
License:
Zope Public License (ZPL) Version 2.1
A copyright notice accompanies this license document that identifies the
copyright holders. This license has been certified as open source. It has
also been designated as GPL compatible by the Free Software Foundation (FSF).
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions in source code must retain the accompanying copyright
notice, this list of conditions, and the following disclaimer.
2. Redistributions in binary form must reproduce the accompanying
copyright notice, this list of conditions, and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
3. Names of the copyright holders must not be used to endorse or promote
products derived from this software without prior written permission from
the copyright holders.
4. The right to distribute this software or to use it for any purpose does
not give you the right to use Servicemarks (sm) or Trademarks (tm) of the
copyright holders. Use of them is covered by separate agreement with the
copyright holders.
5. If any files are modified, you must cause the modified files to carry
prominent notices stating that you changed the files and the date of any
change.
Disclaimer
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ThreadPool is: ThreadPool is:
Copyright (c) Morten Holdflod Moeller Copyright (c) Morten Holdflod Moeller
@ -210,3 +253,4 @@ License:
apply, that proxy's public statement of acceptance of any version is apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the permanent authorization for you to choose that version for the
Library. Library.

1
debian/pycompat vendored Normal file
View file

@ -0,0 +1 @@
2

1
debian/rules vendored Executable file → Normal file
View file

@ -1,3 +1,4 @@
#!/usr/bin/make -f #!/usr/bin/make -f
%: %:
dh $@ dh $@

View file

@ -7,4 +7,4 @@ Type=Application
Exec=trimage Exec=trimage
Categories=Application;Qt;Graphics; Categories=Application;Qt;Graphics;
StartupNotify=true StartupNotify=true
Keywords=compression;compressor;images;jpg;jpeg;png;web;

View file

@ -3,7 +3,7 @@
.\" This manual page is distributed under the terms .\" This manual page is distributed under the terms
.\" of the GNU Free Documentation License version 1.3. .\" of the GNU Free Documentation License version 1.3.
.\" .\"
.TH TRIMAGE "1" "2019-03-12" "trimage 1.0.6" "User Commands" .TH TRIMAGE "1" "2011-07-11" "trimage 1.0.5" "User Commands"
.SH NAME .SH NAME
trimage \- losslessly optimizing png and jpeg liles trimage \- losslessly optimizing png and jpeg liles

37
resources/todo Normal file
View file

@ -0,0 +1,37 @@
==========================================
todo app wise
- general refactoring
- sys.exit(1) for errors -- how to handle? Not good to simply sys.exit() from
any random part of code (can leave things in a mess)
- consider context managers for handling compression, so as to keep operations
atomic and/or rollback-able
- add a recursive option on the command-line for use with -d
- make -f accept a list of files
- make the current verbose be "normal", and make -verbose print the commandline
app prints as well
- find a way to specify the version once for everywhere
- notification area drag/drop widget
-> probably need gtk for gnome
todo else
- figure out how to make mac and win versions (someone else :) <- via gui2exe
===========================================
later versions:
animate compressing.gif
allow selection/deletion of rows from table (and subsequently the imagelist)
punypng api? http://www.gracepointafterfive.com/punypng/api
imagemagick/graphicsmagick?
always on top option
intelligently recompress, i.e. go through the list of files, recompress
each until no more gains are seen (and a sensible number-of-tries limit
isn't exceeded), and flag that file as fully-optimised. Repeat for each
file in the list, until all are done. Saves pointlessly trying to
optimise files. Consider the case of a directory of 100 files, already
optimised once. Recompressing maximally compresses 90. Recompressing
again would currently try to recompress all 100, when only 10 would be
worthy of trying to compress further.

View file

@ -1,22 +1,41 @@
#!/usr/bin/env python3 #!/usr/bin/env python
import sys
win=(sys.platform == "win32")
if win:
import py2exe
sys.path.append("src/trimage")
from distutils.core import setup from distutils.core import setup
setup(name = "trimage", setup(name = "trimage",
version = "1.0.6", version = "1.0.2",
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",
author = "Kilian Valkhof, Paul Chaplin", author = "Kilian Valkhof, Paul Chaplin",
author_email = "help@trimage.org", author_email = "help@trimage.org",
url = "http://trimage.org", url = "http://trimage.org",
license = "MIT license", license = "MIT license",
package_dir = {'trimage' : 'src/trimage'},
packages = ["trimage", packages = ["trimage",
"trimage.ThreadPool"], "trimage.filesize",
"trimage.ThreadPool",],
package_data = {"trimage" : ["pixmaps/*.*"] }, package_data = {"trimage" : ["pixmaps/*.*"] },
data_files=[('share/icons/hicolor/scalable/apps', ['desktop/trimage.svg']), data_files=[('share/icons/hicolor/scalable/apps', ['desktop/trimage.svg']),
('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 = ["trimage"],
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.""", 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.""",
requires = ["PyQt5"] requires = ["PyQt4 (>=4.4)"],
#for py2exe
windows=[r'src\trimage\trimage.py'],
zipfile=None,
options={"py2exe":{
"optimize":2,
"compressed":1,
"bundle_files":1,
"includes":["sip",],
"excludes":['email'],
},
},
) )

View file

@ -1,5 +1,3 @@
#!/usr/bin/env python3
''' '''
ThreadPool Implementation ThreadPool Implementation
@ -10,7 +8,7 @@ ThreadPool Implementation
from __future__ import with_statement from __future__ import with_statement
from threading import Thread, RLock from threading import Thread, RLock
from time import sleep from time import sleep
from queue import Queue, Empty from Queue import Queue, Empty
import logging import logging
import sys import sys
@ -30,6 +28,9 @@ class ThreadPoolMixIn:
def __init__(self, threadpool=None): def __init__(self, threadpool=None):
if (threadpool == None): if (threadpool == None):
threadpool = ThreadPool() threadpool = ThreadPool()
self.__private_threadpool = True
else:
self.__private_threadpool = False
self.__threadpool = threadpool self.__threadpool = threadpool
@ -49,6 +50,10 @@ class ThreadPoolMixIn:
def process_request(self, request, client_address): def process_request(self, request, client_address):
self.__threadpool.add_job(self.process_request_thread, [request, client_address]) self.__threadpool.add_job(self.process_request_thread, [request, client_address])
def shutdown(self):
if (self.__private_threadpool): self.__threadpool.shutdown()
class AddJobException(Exception): class AddJobException(Exception):
''' '''
Exceptoion raised when a Job could not be added Exceptoion raised when a Job could not be added
@ -81,16 +86,16 @@ class ThreadPool:
''' '''
try: try:
return_value = self.callable(*self.arguments) #IGNORE:W0142 return_value = self.callable(*self.arguments) #IGNORE:W0142
except Exception as excep: #IGNORE:W0703 except Exception, excep: #IGNORE:W0703
logger = logging.getLogger("threadpool.worker") logger = logging.getLogger("threadpool.worker")
logger.warning("A job in the ThreadPool raised an exception: ", excep) logger.warning("A job in the ThreadPool raised an exception: " + excep)
#else do nothing cause we don't know what to do... #else do nothing cause we don't know what to do...
return return
try: try:
if (self.return_callback != None): if (self.return_callback != None):
self.return_callback(return_value) self.return_callback(return_value)
except Exception as _: #IGNORE:W0703 everything could go wrong... except Exception, _: #IGNORE:W0703 everything could go wrong...
logger = logging.getLogger('threadpool') logger = logging.getLogger('threadpool')
logger.warning('Error while delivering return value to callback function') logger.warning('Error while delivering return value to callback function')

View file

@ -0,0 +1 @@
from ThreadPool import ThreadPool, ThreadPoolMixIn

View file

@ -0,0 +1,71 @@
Metadata-Version: 1.0
Name: hurry.filesize
Version: 0.9
Summary: A simple Python library for human readable file sizes (or anything sized in bytes).
Home-page: UNKNOWN
Author: Martijn Faassen, Startifact
Author-email: faassen@startifact.com
License: ZPL 2.1
Description: hurry.filesize
==============
hurry.filesize a simple Python library that can take a number of bytes and
returns a human-readable string with the size in it, in kilobytes (K),
megabytes (M), etc.
The default system it uses is "traditional", where multipliers of 1024
increase the unit size::
>>> from hurry.filesize import size
>>> size(1024)
'1K'
An alternative, slightly more verbose system::
>>> from hurry.filesize import alternative
>>> size(1, system=alternative)
'1 byte'
>>> size(10, system=alternative)
'10 bytes'
>>> size(1024, system=alternative)
'1 KB'
A verbose system::
>>> from hurry.filesize import verbose
>>> size(10, system=verbose)
'10 bytes'
>>> size(1024, system=verbose)
'1 kilobyte'
>>> size(2000, system=verbose)
'1 kilobyte'
>>> size(3000, system=verbose)
'2 kilobytes'
>>> size(1024 * 1024, system=verbose)
'1 megabyte'
>>> size(1024 * 1024 * 3, system=verbose)
'3 megabytes'
You can also use the SI system, where multipliers of 1000 increase the unit
size::
>>> from hurry.filesize import si
>>> size(1000, system=si)
'1K'
Changes
=======
0.9 (2009-03-11)
----------------
* Initial public release.
Download
========
Keywords: file size bytes
Platform: UNKNOWN
Classifier: Programming Language :: Python
Classifier: Topic :: Software Development :: Libraries :: Python Modules

View file

@ -0,0 +1,50 @@
hurry.filesize
==============
hurry.filesize a simple Python library that can take a number of bytes and
returns a human-readable string with the size in it, in kilobytes (K),
megabytes (M), etc.
The default system it uses is "traditional", where multipliers of 1024
increase the unit size::
>>> from hurry.filesize import size
>>> size(1024)
'1K'
An alternative, slightly more verbose system::
>>> from hurry.filesize import alternative
>>> size(1, system=alternative)
'1 byte'
>>> size(10, system=alternative)
'10 bytes'
>>> size(1024, system=alternative)
'1 KB'
A verbose system::
>>> from hurry.filesize import verbose
>>> size(10, system=verbose)
'10 bytes'
>>> size(1024, system=verbose)
'1 kilobyte'
>>> size(2000, system=verbose)
'1 kilobyte'
>>> size(3000, system=verbose)
'2 kilobytes'
>>> size(1024 * 1024, system=verbose)
'1 megabyte'
>>> size(1024 * 1024 * 3, system=verbose)
'3 megabytes'
You can also use the SI system, where multipliers of 1000 increase the unit
size::
>>> from hurry.filesize import si
>>> size(1000, system=si)
'1K'
http://pypi.python.org/pypi/hurry.filesize

View file

@ -0,0 +1,2 @@
from filesize import size
from filesize import traditional, alternative, verbose, iec, si

View file

@ -0,0 +1,115 @@
'''
hurry.filesize
@author: Martijn Faassen, Startifact
@license: ZPL 2.1
'''
traditional = [
(1024 ** 5, 'P'),
(1024 ** 4, 'T'),
(1024 ** 3, 'G'),
(1024 ** 2, 'M'),
(1024 ** 1, 'K'),
(1024 ** 0, 'B'),
]
alternative = [
(1024 ** 5, ' PB'),
(1024 ** 4, ' TB'),
(1024 ** 3, ' GB'),
(1024 ** 2, ' MB'),
(1024 ** 1, ' KB'),
(1024 ** 0, (' byte', ' bytes')),
]
verbose = [
(1024 ** 5, (' petabyte', ' petabytes')),
(1024 ** 4, (' terabyte', ' terabytes')),
(1024 ** 3, (' gigabyte', ' gigabytes')),
(1024 ** 2, (' megabyte', ' megabytes')),
(1024 ** 1, (' kilobyte', ' kilobytes')),
(1024 ** 0, (' byte', ' bytes')),
]
iec = [
(1024 ** 5, 'Pi'),
(1024 ** 4, 'Ti'),
(1024 ** 3, 'Gi'),
(1024 ** 2, 'Mi'),
(1024 ** 1, 'Ki'),
(1024 ** 0, ''),
]
si = [
(1000 ** 5, 'P'),
(1000 ** 4, 'T'),
(1000 ** 3, 'G'),
(1000 ** 2, 'M'),
(1000 ** 1, 'K'),
(1000 ** 0, 'B'),
]
def size(bytes, system=traditional):
"""Human-readable file size.
Using the traditional system, where a factor of 1024 is used::
>>> size(10)
'10B'
>>> size(100)
'100B'
>>> size(1000)
'1000B'
>>> size(2000)
'1K'
>>> size(10000)
'9K'
>>> size(20000)
'19K'
>>> size(100000)
'97K'
>>> size(200000)
'195K'
>>> size(1000000)
'976K'
>>> size(2000000)
'1M'
Using the SI system, with a factor 1000::
>>> size(10, system=si)
'10B'
>>> size(100, system=si)
'100B'
>>> size(1000, system=si)
'1K'
>>> size(2000, system=si)
'2K'
>>> size(10000, system=si)
'10K'
>>> size(20000, system=si)
'20K'
>>> size(100000, system=si)
'100K'
>>> size(200000, system=si)
'200K'
>>> size(1000000, system=si)
'1M'
>>> size(2000000, system=si)
'2M'
"""
for factor, suffix in system:
if bytes >= factor:
break
amount = int(bytes/factor)
if isinstance(suffix, tuple):
singular, multiple = suffix
if amount == 1:
suffix = singular
else:
suffix = multiple
return str(amount) + suffix

View file

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 676 B

After

Width:  |  Height:  |  Size: 676 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 2 KiB

After

Width:  |  Height:  |  Size: 2 KiB

Before After
Before After

View file

@ -1,27 +1,32 @@
#!/usr/bin/env python3 #!/usr/bin/python
import time import time
import sys import sys
from os import listdir, path, remove, access, W_OK import errno
from os import listdir
from os import path
from os import remove
from os import access
from os import W_OK as WRITEABLE
from shutil import copy from shutil import copy
from subprocess import call, PIPE
from optparse import OptionParser from optparse import OptionParser
from multiprocessing import cpu_count
from queue import Queue
from PyQt5.QtCore import * from PyQt4.QtCore import *
from PyQt5.QtGui import * from PyQt4.QtGui import *
from PyQt5.QtWidgets import * from filesize import *
from imghdr import what as determinetype
from Queue import Queue
from ThreadPool import ThreadPool from ThreadPool import ThreadPool
from multiprocessing import cpu_count
from ui import Ui_trimage from ui import Ui_trimage
from tools import *
VERSION = "1.0.5"
VERSION = "1.0.6" class StartQT4(QMainWindow):
class StartQt(QMainWindow):
def __init__(self, parent=None): def __init__(self, parent=None):
QWidget.__init__(self, parent) QWidget.__init__(self, parent)
self.ui = Ui_trimage() self.ui = Ui_trimage()
@ -35,14 +40,13 @@ class StartQt(QMainWindow):
QCoreApplication.setOrganizationDomain("trimage.org") QCoreApplication.setOrganizationDomain("trimage.org")
QCoreApplication.setApplicationName("Trimage") QCoreApplication.setApplicationName("Trimage")
self.settings = QSettings() self.settings = QSettings()
if self.settings.value("geometry"): self.restoreGeometry(self.settings.value("geometry").toByteArray())
self.restoreGeometry(self.settings.value("geometry"))
# check if dependencies are installed # check if apps are installed
if not check_dependencies(): if self.checkapps():
quit() quit()
# add quit shortcut #add quit shortcut
if hasattr(QKeySequence, "Quit"): if hasattr(QKeySequence, "Quit"):
self.quit_shortcut = QShortcut(QKeySequence(QKeySequence.Quit), self.quit_shortcut = QShortcut(QKeySequence(QKeySequence.Quit),
self) self)
@ -51,17 +55,23 @@ class StartQt(QMainWindow):
# disable recompress # disable recompress
self.ui.recompress.setEnabled(False) self.ui.recompress.setEnabled(False)
#self.ui.recompress.hide()
# make a worker thread # make a worker thread
self.thread = Worker() self.thread = Worker()
# connect signals with slots # connect signals with slots
self.ui.addfiles.clicked.connect(self.file_dialog) QObject.connect(self.ui.addfiles, SIGNAL("clicked()"),
self.ui.recompress.clicked.connect(self.recompress_files) self.file_dialog)
self.quit_shortcut.activated.connect(self.close) QObject.connect(self.ui.recompress, SIGNAL("clicked()"),
self.ui.processedfiles.drop_event_signal.connect(self.file_drop) self.recompress_files)
self.thread.finished.connect(self.update_table) QObject.connect(self.quit_shortcut, SIGNAL("activated()"),
self.thread.update_ui_signal.connect(self.update_table) qApp, SLOT('quit()'))
QObject.connect(self.ui.processedfiles, SIGNAL("fileDropEvent"),
self.file_drop)
QObject.connect(self.thread, SIGNAL("finished()"), self.update_table)
QObject.connect(self.thread, SIGNAL("terminated()"), self.update_table)
QObject.connect(self.thread, SIGNAL("updateUi"), self.update_table)
self.compressing_icon = QIcon(QPixmap(self.ui.get_image("pixmaps/compressing.gif"))) self.compressing_icon = QIcon(QPixmap(self.ui.get_image("pixmaps/compressing.gif")))
@ -72,11 +82,11 @@ class StartQt(QMainWindow):
self.systemtray = Systray(self) self.systemtray = Systray(self)
def commandline_options(self): def commandline_options(self):
"""Set up the command line options."""
self.cli = False self.cli = False
"""Set up the command line options."""
parser = OptionParser(version="%prog " + VERSION, parser = OptionParser(version="%prog " + VERSION,
description="GUI front-end to compress png and jpg images via " description="GUI front-end to compress png and jpg images via "
"advpng, jpegoptim, optipng and pngcrush") "optipng, advpng and jpegoptim")
parser.set_defaults(verbose=True) parser.set_defaults(verbose=True)
parser.add_option("-v", "--verbose", action="store_true", parser.add_option("-v", "--verbose", action="store_true",
@ -93,14 +103,14 @@ class StartQt(QMainWindow):
# make sure we quit after processing finished if using cli # make sure we quit after processing finished if using cli
if options.filename or options.directory: if options.filename or options.directory:
self.thread.finished.connect(quit) QObject.connect(self.thread, SIGNAL("finished()"), quit)
self.cli = True self.cli = True
# send to correct function # send to correct function
if options.filename: if options.filename:
self.file_from_cmd(options.filename) self.file_from_cmd(options.filename.decode("utf-8"))
if options.directory: if options.directory:
self.dir_from_cmd(options.directory) self.dir_from_cmd(options.directory.decode("utf-8"))
self.verbose = options.verbose self.verbose = options.verbose
@ -133,12 +143,11 @@ class StartQt(QMainWindow):
def file_dialog(self): def file_dialog(self):
"""Open a file dialog and send the selected images to compress_file.""" """Open a file dialog and send the selected images to compress_file."""
fd = QFileDialog(self) fd = QFileDialog(self)
if (self.settings.value("fdstate")): fd.restoreState(self.settings.value("fdstate").toByteArray())
fd.restoreState(self.settings.value("fdstate")) directory = self.settings.value("directory", QVariant("")).toString()
directory = self.settings.value("directory", QVariant(""))
fd.setDirectory(directory) fd.setDirectory(directory)
images, _ = fd.getOpenFileNames(self, images = fd.getOpenFileNames(self,
"Select one or more image files to compress", "Select one or more image files to compress",
directory, directory,
# this is a fix for file dialog differentiating between cases # this is a fix for file dialog differentiating between cases
@ -146,8 +155,8 @@ class StartQt(QMainWindow):
self.settings.setValue("fdstate", QVariant(fd.saveState())) self.settings.setValue("fdstate", QVariant(fd.saveState()))
if images: if images:
self.settings.setValue("directory", QVariant(path.dirname(images[0]))) self.settings.setValue("directory", QVariant(path.dirname(unicode(images[0]))))
self.delegator([fullpath for fullpath in images]) self.delegator([unicode(fullpath) for fullpath in images])
def recompress_files(self): def recompress_files(self):
"""Send each file in the current file list to compress_file again.""" """Send each file in the current file list to compress_file again."""
@ -164,15 +173,15 @@ class StartQt(QMainWindow):
delegatorlist = [] delegatorlist = []
for fullpath in images: for fullpath in images:
try: # recompress images already in the list try: # recompress images already in the list
image = next(i.image for i in self.imagelist image = (i.image for i in self.imagelist
if i.image.fullpath == fullpath) if i.image.fullpath == fullpath).next()
if image.compressed: if image.compressed:
image.reset() image.reset()
image.recompression = True image.recompression = True
delegatorlist.append(image) delegatorlist.append(image)
except StopIteration: except StopIteration:
if not path.isdir(fullpath): if not path.isdir(fullpath):
self.add_image(fullpath, delegatorlist) self. add_image(fullpath, delegatorlist)
else: else:
self.walk(fullpath, delegatorlist) self.walk(fullpath, delegatorlist)
@ -182,7 +191,7 @@ class StartQt(QMainWindow):
def walk(self, dir, delegatorlist): def walk(self, dir, delegatorlist):
""" """
Walks a directory, and executes a callback on each file. Walks a directory, and executes a callback on each file
""" """
dir = path.abspath(dir) dir = path.abspath(dir)
for file in [file for file in listdir(dir) if not file in [".","..",".svn",".git",".hg",".bzr",".cvs"]]: for file in [file for file in listdir(dir) if not file in [".","..",".svn",".git",".hg",".bzr",".cvs"]]:
@ -195,7 +204,7 @@ class StartQt(QMainWindow):
def add_image(self, fullpath, delegatorlist): def add_image(self, fullpath, delegatorlist):
""" """
Adds an image file to the delegator list and update the tray and the title of the window. Adds an image file to the delegator list and update the tray and the title of the window
""" """
image = Image(fullpath) image = Image(fullpath)
if image.valid: if image.valid:
@ -205,7 +214,7 @@ class StartQt(QMainWindow):
self.systemtray.trayIcon.setToolTip("Trimage image compressor (" + str(len(self.imagelist)) + " files)") self.systemtray.trayIcon.setToolTip("Trimage image compressor (" + str(len(self.imagelist)) + " files)")
self.setWindowTitle("Trimage image compressor (" + str(len(self.imagelist)) + " files)") self.setWindowTitle("Trimage image compressor (" + str(len(self.imagelist)) + " files)")
else: else:
print("[error] {} not a supported image file and/or not writable".format(image.fullpath), file=sys.stderr) print >> sys.stderr, u"[error] %s not a supported image file and/or not writeable" % image.fullpath
""" """
UI Functions UI Functions
@ -238,12 +247,52 @@ class StartQt(QMainWindow):
# enable recompress button # enable recompress button
self.enable_recompress() self.enable_recompress()
"""
Helper functions
"""
def enable_recompress(self): def enable_recompress(self):
"""Enable the recompress button.""" """Enable the recompress button."""
self.ui.recompress.setEnabled(True) self.ui.recompress.setEnabled(True)
if QSystemTrayIcon.isSystemTrayAvailable() and not self.cli: if QSystemTrayIcon.isSystemTrayAvailable() and not self.cli:
self.systemtray.recompress.setEnabled(True) self.systemtray.recompress.setEnabled(True)
def checkapps(self):
"""Check if the required command line apps exist."""
exe = ".exe" if (sys.platform == "win32") else ""
status = False
retcode = self.safe_call("jpegoptim" + exe + " --version")
if retcode != 0:
status = True
sys.stderr.write("[error] please install jpegoptim")
retcode = self.safe_call("optipng" + exe + " -v")
if retcode != 0:
status = True
sys.stderr.write("[error] please install optipng")
retcode = self.safe_call("advpng" + exe + " --version")
if retcode != 0:
status = True
sys.stderr.write("[error] please install advancecomp")
retcode = self.safe_call("pngcrush" + exe + " -version")
if retcode != 0:
status = True
sys.stderr.write("[error] please install pngcrush")
return status
def safe_call(self, command):
""" cross-platform command-line check """
while True:
try:
return call(command, shell=True, stdout=PIPE)
except OSError, e:
if e.errno == errno.EINTR:
continue
else:
raise
def hide_main_window(self): def hide_main_window(self):
if self.isVisible(): if self.isVisible():
self.hide() self.hide()
@ -260,6 +309,7 @@ class StartQt(QMainWindow):
class TriTableModel(QAbstractTableModel): class TriTableModel(QAbstractTableModel):
def __init__(self, parent, imagelist, header, *args): def __init__(self, parent, imagelist, header, *args):
""" """
@param parent Qt parent object. @param parent Qt parent object.
@ -301,15 +351,15 @@ class TriTableModel(QAbstractTableModel):
class ImageRow: class ImageRow:
def __init__(self, image, waitingIcon=None):
"""Build the information visible in the table image row."""
self.image = image
def __init__(self, image, waitingIcon=None):
""" Build the information visible in the table image row. """
self.image = image
d = { d = {
'filename_w_ext': lambda i: self.statusStr().format(i.filename_w_ext), 'shortname': lambda i: self.statusStr() % i.shortname,
'oldfilesizestr': lambda i: human_readable_size(i.oldfilesize) 'oldfilesizestr': lambda i: size(i.oldfilesize, system=alternative)
if i.compressed else "", if i.compressed else "",
'newfilesizestr': lambda i: human_readable_size(i.newfilesize) 'newfilesizestr': lambda i: size(i.newfilesize, system=alternative)
if i.compressed else "", if i.compressed else "",
'ratiostr': lambda i: 'ratiostr': lambda i:
"%.1f%%" % (100 - (float(i.newfilesize) / i.oldfilesize * 100)) "%.1f%%" % (100 - (float(i.newfilesize) / i.oldfilesize * 100))
@ -317,7 +367,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 = ['filename_w_ext', 'oldfilesizestr', 'newfilesizestr', names = ['shortname', '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]
@ -325,40 +375,47 @@ class ImageRow:
self.d = d self.d = d
def statusStr(self): def statusStr(self):
"""Set the status message.""" """ Set the status message. """
if self.image.failed: if self.image.failed:
return "ERROR: {0}" return "ERROR: %s"
if self.image.compressing: if self.image.compressing:
message = "Compressing {0}..." message = "Compressing %s..."
return message return message
if not self.image.compressed and self.image.recompression: if not self.image.compressed and self.image.recompression:
return "Queued for recompression {0}..." return "Queued for recompression..."
if not self.image.compressed: if not self.image.compressed:
return "Queued {0}..." return "Queued..."
return "{0}" return "%s"
def __getitem__(self, key): def __getitem__(self, key):
return self.d[key](self.image) return self.d[key](self.image)
class Image: class Image:
def __init__(self, fullpath): def __init__(self, fullpath):
"""Gather image information.""" """ gather image information. """
self.valid = False self.valid = False
self.reset() self.reset()
self.fullpath = fullpath self.fullpath = fullpath
self.filename_w_ext = path.basename(self.fullpath) if path.isfile(self.fullpath) and access(self.fullpath, WRITEABLE):
self.filename, self.filetype = path.splitext(self.filename_w_ext) self.filetype = determinetype(self.fullpath)
if path.isfile(self.fullpath) and access(self.fullpath, W_OK):
self.filetype = self.filetype[1:].lower()
if self.filetype == "jpg":
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
#def _determinetype(self):
# """ Determine the filetype of the file using imghdr. """
# filetype = determinetype(self.fullpath)
# if filetype in ["jpeg", "png"]:
# self.filetype = filetype
# else:
# self.filetype = None
# return self.filetype
def reset(self): def reset(self):
self.failed = False self.failed = False
self.compressed = False self.compressed = False
@ -366,19 +423,19 @@ class Image:
self.recompression = False self.recompression = False
def compress(self): def compress(self):
"""Compress the image and return it to the thread.""" """ Compress the image and return it to the thread. """
if not self.valid: if not self.valid:
raise "Tried to compress invalid image (unsupported format or not \ raise "Tried to compress invalid image (unsupported format or not \
file)" file)"
self.reset() self.reset()
self.compressing = True self.compressing = True
exe = ".exe" if (sys.platform == "win32") else ""
runString = { runString = {
"jpeg": "jpegoptim -f --strip-all '%(file)s'", "jpeg": u"jpegoptim" + exe + " -f --strip-all '%(file)s'",
"png": "optipng -force -o7 '%(file)s'&&advpng -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": u"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
backupfullpath = '/tmp/' + self.filename_w_ext copy(self.fullpath, self.fullpath + '~')
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,13 +445,13 @@ class Image:
self.newfilesize = QFile(self.fullpath).size() self.newfilesize = QFile(self.fullpath).size()
self.compressed = True self.compressed = True
# 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(backupfullpath, self.fullpath) copy(self.fullpath + '~', self.fullpath)
self.newfilesize = self.oldfilesize self.newfilesize = self.oldfilesize
# removes the backup file # Removes the backup file
remove(backupfullpath) remove(self.fullpath + '~')
else: else:
self.failed = True self.failed = True
self.compressing = False self.compressing = False
@ -403,13 +460,15 @@ class Image:
class Worker(QThread): class Worker(QThread):
update_ui_signal = pyqtSignal()
def __init__(self, parent=None): def __init__(self, parent=None):
QThread.__init__(self, parent) QThread.__init__(self, parent)
self.toDisplay = Queue() self.toDisplay = Queue()
self.threadpool = ThreadPool(max_workers=cpu_count()) self.threadpool = ThreadPool(max_workers=cpu_count())
def __del__(self):
self.threadpool.shutdown()
def compress_file(self, images, showapp, verbose, imagelist): def compress_file(self, images, showapp, verbose, imagelist):
"""Start the worker thread.""" """Start the worker thread."""
for image in images: for image in images:
@ -429,7 +488,7 @@ class Worker(QThread):
tp._ThreadPool__jobs.empty()): tp._ThreadPool__jobs.empty()):
image = self.toDisplay.get() image = self.toDisplay.get()
self.update_ui_signal.emit() self.emit(SIGNAL("updateUi"))
if not self.showapp and self.verbose: # we work via the commandline if not self.showapp and self.verbose: # we work via the commandline
if image.retcode == 0: if image.retcode == 0:
@ -438,10 +497,11 @@ class Worker(QThread):
+ ir['oldfilesizestr'] + ", New Size: " + ir['oldfilesizestr'] + ", New Size: "
+ ir['newfilesizestr'] + ", Ratio: " + ir['ratiostr']) + ir['newfilesizestr'] + ", Ratio: " + ir['ratiostr'])
else: else:
print("[error] {} could not be compressed".format(image.fullpath), file=sys.stderr) print >> sys.stderr, u"[error] %s could not be compressed" % image.fullpath
class Systray(QWidget): class Systray(QWidget):
def __init__(self, parent): def __init__(self, parent):
QWidget.__init__(self) QWidget.__init__(self)
self.parent = parent self.parent = parent
@ -451,14 +511,15 @@ class Systray(QWidget):
def createActions(self): def createActions(self):
self.quitAction = QAction(self.tr("&Quit"), self) self.quitAction = QAction(self.tr("&Quit"), self)
self.quitAction.triggered.connect(self.parent.close) QObject.connect(self.quitAction, SIGNAL("triggered()"),
qApp, SLOT("quit()"))
self.addFiles = QAction(self.tr("&Add and compress"), self) self.addFiles = QAction(self.tr("&Add and compress"), self)
icon = QIcon() icon = QIcon()
icon.addPixmap(QPixmap(self.parent.ui.get_image(("pixmaps/list-add.png"))), icon.addPixmap(QPixmap(self.parent.ui.get_image(("pixmaps/list-add.png"))),
QIcon.Normal, QIcon.Off) QIcon.Normal, QIcon.Off)
self.addFiles.setIcon(icon) self.addFiles.setIcon(icon)
self.addFiles.triggered.connect(self.parent.file_dialog) QObject.connect(self.addFiles, SIGNAL("triggered()"), self.parent.file_dialog)
self.recompress = QAction(self.tr("&Recompress"), self) self.recompress = QAction(self.tr("&Recompress"), self)
icon2 = QIcon() icon2 = QIcon()
@ -466,11 +527,10 @@ class Systray(QWidget):
QIcon.Normal, QIcon.Off) QIcon.Normal, QIcon.Off)
self.recompress.setIcon(icon2) self.recompress.setIcon(icon2)
self.recompress.setDisabled(True) self.recompress.setDisabled(True)
QObject.connect(self.addFiles, SIGNAL("triggered()"), self.parent.recompress_files)
self.addFiles.triggered.connect(self.parent.recompress_files)
self.hideMain = QAction(self.tr("&Hide window"), self) self.hideMain = QAction(self.tr("&Hide window"), self)
self.hideMain.triggered.connect(self.parent.hide_main_window) QObject.connect(self.hideMain, SIGNAL("triggered()"), self.parent.hide_main_window)
def createTrayIcon(self): def createTrayIcon(self):
self.trayIconMenu = QMenu(self) self.trayIconMenu = QMenu(self)
@ -490,7 +550,7 @@ class Systray(QWidget):
if __name__ == "__main__": if __name__ == "__main__":
app = QApplication(sys.argv) app = QApplication(sys.argv)
myapp = StartQt() myapp = StartQT4()
if myapp.showapp: if myapp.showapp:
myapp.show() myapp.show()

View file

@ -1,16 +1,8 @@
#!/usr/bin/env python3 from PyQt4.QtCore import *
from PyQt4.QtGui import *
from os import path from os import path
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
class TrimageTableView(QTableView): class TrimageTableView(QTableView):
drop_event_signal = pyqtSignal(list)
"""Init the table drop event.""" """Init the table drop event."""
def __init__(self, parent=None): def __init__(self, parent=None):
super(TrimageTableView, self).__init__(parent) super(TrimageTableView, self).__init__(parent)
@ -29,19 +21,19 @@ class TrimageTableView(QTableView):
event.accept() event.accept()
filelist = [] filelist = []
for url in event.mimeData().urls(): for url in event.mimeData().urls():
filelist.append(url.toLocalFile()) filelist.append(unicode(url.toLocalFile()))
self.drop_event_signal.emit(filelist) self.emit(SIGNAL("fileDropEvent"), (filelist))
class Ui_trimage(): class Ui_trimage(object):
def get_image(self, image): def get_image(self, image):
"""Get the correct link to the images used in the UI.""" """ Get the correct link to the images used in the UI """
imagelink = path.join(path.dirname(path.dirname(path.realpath(__file__))), "trimage/" + image) imagelink = path.join(path.dirname(path.dirname(path.realpath(__file__))), "trimage/" + image)
return imagelink return imagelink
def setupUi(self, trimage): def setupUi(self, trimage):
"""Setup the entire UI.""" """ Setup the entire UI """
trimage.setObjectName("trimage") trimage.setObjectName("trimage")
trimage.resize(600, 170) trimage.resize(600, 170)
@ -52,7 +44,7 @@ class Ui_trimage():
self.centralwidget.setObjectName("centralwidget") self.centralwidget.setObjectName("centralwidget")
self.gridLayout_2 = QGridLayout(self.centralwidget) self.gridLayout_2 = QGridLayout(self.centralwidget)
self.gridLayout_2.setContentsMargins(0, 0, 0, 0) self.gridLayout_2.setMargin(0)
self.gridLayout_2.setSpacing(0) self.gridLayout_2.setSpacing(0)
self.gridLayout_2.setObjectName("gridLayout_2") self.gridLayout_2.setObjectName("gridLayout_2")
@ -68,7 +60,7 @@ class Ui_trimage():
self.verticalLayout = QVBoxLayout(self.widget) self.verticalLayout = QVBoxLayout(self.widget)
self.verticalLayout.setSpacing(0) self.verticalLayout.setSpacing(0)
self.verticalLayout.setContentsMargins(0, 0, 0, 0) self.verticalLayout.setMargin(0)
self.verticalLayout.setObjectName("verticalLayout") self.verticalLayout.setObjectName("verticalLayout")
self.frame = QFrame(self.widget) self.frame = QFrame(self.widget)
@ -76,12 +68,12 @@ class Ui_trimage():
self.verticalLayout_2 = QVBoxLayout(self.frame) self.verticalLayout_2 = QVBoxLayout(self.frame)
self.verticalLayout_2.setSpacing(0) self.verticalLayout_2.setSpacing(0)
self.verticalLayout_2.setContentsMargins(0, 0, 0, 0) self.verticalLayout_2.setMargin(0)
self.verticalLayout_2.setObjectName("verticalLayout_2") self.verticalLayout_2.setObjectName("verticalLayout_2")
self.horizontalLayout = QHBoxLayout() self.horizontalLayout = QHBoxLayout()
self.horizontalLayout.setSpacing(0) self.horizontalLayout.setSpacing(0)
self.horizontalLayout.setContentsMargins(10, 10, 10, 10) self.horizontalLayout.setMargin(10)
self.horizontalLayout.setObjectName("horizontalLayout") self.horizontalLayout.setObjectName("horizontalLayout")
self.addfiles = QPushButton(self.frame) self.addfiles = QPushButton(self.frame)
@ -101,7 +93,7 @@ class Ui_trimage():
font.setPointSize(8) font.setPointSize(8)
self.label.setFont(font) self.label.setFont(font)
self.label.setFrameShadow(QFrame.Plain) self.label.setFrameShadow(QFrame.Plain)
self.label.setContentsMargins(1, 1, 1, 1) self.label.setMargin(1)
self.label.setIndent(10) self.label.setIndent(10)
self.label.setObjectName("label") self.label.setObjectName("label")
self.horizontalLayout.addWidget(self.label) self.horizontalLayout.addWidget(self.label)
@ -149,24 +141,26 @@ class Ui_trimage():
QMetaObject.connectSlotsByName(trimage) QMetaObject.connectSlotsByName(trimage)
def retranslateUi(self, trimage): def retranslateUi(self, trimage):
"""Fill in the texts for all UI elements.""" """ Fill in the texts for all UI elements """
trimage.setWindowTitle(QApplication.translate("trimage", trimage.setWindowTitle(QApplication.translate("trimage",
"Trimage image compressor", None)) "Trimage image compressor", None, QApplication.UnicodeUTF8))
self.addfiles.setToolTip(QApplication.translate("trimage", self.addfiles.setToolTip(QApplication.translate("trimage",
"Add file to the compression list", None)) "Add file to the compression list", None,
QApplication.UnicodeUTF8))
self.addfiles.setText(QApplication.translate("trimage", self.addfiles.setText(QApplication.translate("trimage",
"&Add and compress", None)) "&Add and compress", None, QApplication.UnicodeUTF8))
self.addfiles.setShortcut(QApplication.translate("trimage", self.addfiles.setShortcut(QApplication.translate("trimage",
"Alt+A", None)) "Alt+A", None, QApplication.UnicodeUTF8))
self.label.setText(QApplication.translate("trimage", self.label.setText(QApplication.translate("trimage",
"Drag and drop images onto the table", None)) "Drag and drop images onto the table", None,
QApplication.UnicodeUTF8))
self.recompress.setToolTip(QApplication.translate("trimage", self.recompress.setToolTip(QApplication.translate("trimage",
"Recompress all images", None)) "Recompress all images", None, QApplication.UnicodeUTF8))
self.recompress.setText(QApplication.translate("trimage", self.recompress.setText(QApplication.translate("trimage",
"&Recompress", None)) "&Recompress", None, QApplication.UnicodeUTF8))
self.recompress.setShortcut(QApplication.translate("trimage", self.recompress.setShortcut(QApplication.translate("trimage",
"Alt+R", None)) "Alt+R", None, QApplication.UnicodeUTF8))
self.processedfiles.setToolTip(QApplication.translate("trimage", self.processedfiles.setToolTip(QApplication.translate("trimage",
"Drag files in here", None)) "Drag files in here", None, QApplication.UnicodeUTF8))
self.processedfiles.setWhatsThis(QApplication.translate("trimage", self.processedfiles.setWhatsThis(QApplication.translate("trimage",
"Drag files in here", None)) "Drag files in here", None, QApplication.UnicodeUTF8))

View file

@ -1,4 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python
#coding: utf-8
# #
#Copyright (c) 2010 Kilian Valkhof, Paul Chaplin, Tarnay Kálmán #Copyright (c) 2010 Kilian Valkhof, Paul Chaplin, Tarnay Kálmán
# #

View file

@ -1 +0,0 @@
from .ThreadPool import ThreadPool, ThreadPoolMixIn

View file

@ -1,45 +0,0 @@
#!/usr/bin/env python3
import sys
import errno
from subprocess import call, PIPE
def check_dependencies():
"""Check if the required command line apps exist."""
status = True
dependencies = {
"jpegoptim": "--version",
"optipng": "-v",
"advpng": "--version",
"pngcrush": "-version"
}
for elt in dependencies:
retcode = safe_call(elt + " " + dependencies[elt])
if retcode != 0:
status = False
print("[error] please install {}".format(elt), file=sys.stderr)
return status
def safe_call(command):
"""Cross-platform command-line check."""
while True:
try:
return call(command, shell=True, stdout=PIPE)
except OSError as e:
if e.errno == errno.EINTR:
continue
else:
raise
def human_readable_size(num, suffix="B"):
"""Bytes to a readable size format"""
for unit in ["", "K", "M", "G", "T", "P", "E", "Z"]:
if abs(num) < 1024.0:
return "%3.1f%s%s" % (num, unit, suffix)
num /= 1024.0
return "%.1f%s%s" % (num, "Y", suffix)

View file

@ -1,18 +1,13 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<meta charset="utf8" /> <meta charset="utf8">
<title>Trimage (lossless) image compressor</title> <title>Trimage (lossless) image compressor</title>
<link <link href="https://raw.github.com/Kilian/sencss/master/source/sen.css" rel="stylesheet" type="text/css">
href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css"
rel="stylesheet"
type="text/css"
/>
<style> <style>
body { body {
background:#fff background:#fff
font-size:13px; font-size:13px;
font-family:sans-serif;
} }
#wrap { #wrap {
position:relative; position:relative;
@ -72,105 +67,83 @@
</style> </style>
</head> </head>
<body> <body>
<div id="wrap"> <div id="wrap">
<h1> <h1><img src="trimage-icon.png" alt=""> Trimage image compressor &ndash; 1.0.5</h1>
<img src="trimage-icon.png" alt="" /> Trimage image compressor &ndash; <span class="subtitle">A cross-platform tool for losslessly optimizing PNG and JPG files.</span>
1.0.6 <p class="tri">Trimage is a cross-platform GUI and command-line interface to optimize image
</h1> files for websites, using <a href="http://optipng.sourceforge.net/">optipng</a>, <a href="http://pmt.sourceforge.net/pngcrush/">pngcrush</a>,
<span class="subtitle" <a href="http://advancemame.sourceforge.net/comp-readme.html">advpng</a> and
>A cross-platform tool for losslessly optimizing PNG and JPG files for <a href="http://www.kokkonen.net/tjko/projects.html">jpegoptim</a>, depending on the filetype
web.</span (currently, PNG and JPG files are supported). It was inspired by
> <a href="http://imageoptim.pornel.net/">imageoptim</a>. All image files are losslessy compressed
<p class="tri"> on the highest available compression levels, and EXIF and other metadata is removed. Trimage gives you various input functions to fit your
Trimage is a cross-platform GUI and command-line interface to optimize own workflow: A regular file dialog, dragging and dropping and various command line options.</p>
image files for websites, using
<a href="http://optipng.sourceforge.net/">optipng</a>,
<a href="http://pmt.sourceforge.net/pngcrush/">pngcrush</a>,
<a href="http://advancemame.sourceforge.net/comp-readme.html">advpng</a>
and <a href="http://www.kokkonen.net/tjko/projects.html">jpegoptim</a>,
depending on the filetype (currently, PNG and JPG files are supported).
It was inspired by
<a href="http://imageoptim.pornel.net/">imageoptim</a>. All image files
are losslessy compressed on the highest available compression levels,
and EXIF and other metadata is removed. Trimage gives you various input
functions to fit your own workflow: A regular file dialog, dragging and
dropping and various command line options.
</p>
<h2>Trimage in action</h2> <h2>Trimage in action</h2>
<img src="image.png" alt="a screenshot of Trimage" /> <img src="image.png" alt="a screenshot of Trimage">
<div class="block2"> <div class="block2">
<h2>Download</h2> <h2>Download</h2>
<h3><img src="debian.png" alt="" /> Debian (sid)</h3> <h3><img src="debian.png" alt=""> Debian (sid)</h3>
<p>Trimage is available in the official Debian Sid repositories:</p> <p>Trimage is available in the official Debian Sid repositories:</p>
<ol> <ol>
<li><code>sudo apt-get install trimage</code></li> <li><code>sudo apt-get install trimage</code></li>
</ol> </ol>
<h3><img src="ubuntu.png" alt="" /> Ubuntu</h3> <h3><img src="ubuntu.png" alt=""> Ubuntu</h3>
<p>Trimage is available in the official repositories:</p> <p>If you're on Natty (11.04), Trimage is available in the official repositories:</p>
<a href="https://apps.ubuntu.com/cat/applications/trimage/" <a href="https://apps.ubuntu.com/cat/applications/trimage/"><img src="http://developer.ubuntu.com/wp-content/uploads/2012/06/downloadonubuntubutton.png" title="Download for Ubuntu" alt="Download for Ubuntu button" width="122" height="49" /></a>
>Download for Ubuntu</a
>
<p>Alternatively:</p> <p>Alternatively:</p>
<ol> <ol>
<li><code>sudo apt-get install trimage</code></li> <li><code>sudo apt-get install trimage</code></li>
</ol> </ol>
<p>If you're on Maveric (10.10), Karmic (9.10) or Lucid (10.04), type the following commands into your console:</p>
<ol>
<li><code>sudo add-apt-repository ppa:kilian/trimage</code></li>
<li><code>sudo apt-get update</code></li>
<li><code>sudo apt-get install trimage</code></li>
</ol>
<p>If you are still on Jaunty, read <a href="https://launchpad.net/+help/soyuz/ppa-sources-list.html">this guide</a> on installing PPA's.</p>
<h3><img src="arch.png" alt="" /> Arch Linux</h3> <h3><img src="arch.png" alt=""> Arch Linux</h3>
Trimage is available from AUR, to install, type: Trimage is available from AUR, to install, type:
<ol> <ol>
<li><code>yaourt -S trimage</code></li> <li><code>yaourt -S trimage-git</code> </li>
</ol> </ol>
<h3><img src="mandriva.png" alt=""> Mandriva Linux 2010.1</h3>
<h3><img src="macos.png" alt="" /> macOS</h3><!-- Attribution for the image: VICDJES21 / CC BY-SA (https://creativecommons.org/licenses/by-sa/4.0) --> Trimage is available Via two RPMs provided by <a href="http://mib.pianetalinux.org/mib/quick/basic-rpms/mib-rpms/918-trimage-105">Mandriva international backports</a>
Trimage is available from Homebrew, to install, type:
<ol> <ol>
<li><code>brew install trimage</code></li> <li><a href="http://mib.pianetalinux.org/2010.1/32/basic/trimage-1.0.5-69mib2010.1.noarch.rpm">Trimage 1.0.5 32bit</a></li>
<li><a href="http://mib.pianetalinux.org/2010.1/64/basic/trimage-1.0.5-69mib2010.1.noarch.rpm">Trimage 1.0.5 63bit</a></li>
</ol> </ol>
<p>Launch by executing <code>trimage</code> in Terminal.app</p> <h3><img src="opensuse.png" alt=""> OpenSuse</h3>
<p>Trimage is available for a variety of versions: 11.3, 11.4 and Factory and SLE. You can find them on <a href="http://software.opensuse.org/search?q=Trimage&include_home=true">software.opensuse.org</a>.</p>
<h3><img src="linux.png" alt="" /> Other *nix</h3> <h3><img src="linux.png" alt=""> Other *nix</h3>
<ol> <ol>
<li>Download the source via git or bzr (see repositories)</li> <li>Download the source via git or bzr (see repositories)</li>
<li> <li>Make sure you have all the requirements installed (see requirements)</li>
Make sure you have all the requirements installed (see requirements)
</li>
<li>Enter <code>python setup.py install</code> into your console</li> <li>Enter <code>python setup.py install</code> into your console</li>
<li>Launch by executing <code>trimage</code></li> <li>Launch by executing <code>trimage</code></li>
</ol> </ol>
<p> <p>Help us make .deb's, rpms's etc: <a href="mailto:help@trimage.org">contact us</a></p>
Help us make .snaps, .appimages etc: <h3><img src="mac.png" alt=""> Mac</h3>
<a href="mailto:help@trimage.org">contact us</a> or <p>Trimage should be able to run on Mac. <a href="mailto:help@trimage.org">Help us with this</a></p>
<a href="https://github.com/kilian/trimage/pulls"
>open a pull request</a
>
</p>
<!--
<h3><img src="windows.png" alt=""> Windows</h3> <h3><img src="windows.png" alt=""> Windows</h3>
<p>Trimage should be able to run on Windows. <a href="mailto:help@trimage.org">Help us with this</a></p> <p>Trimage should be able to run on Windows. <a href="mailto:help@trimage.org">Help us with this</a></p>
-->
</div> </div>
<div class="block"> <div class="block">
<h2>Repositories</h2> <h2>Repositories</h2>
<p> <p><strong>Git:</strong> Trimage is primarily developed on <a href="http://github.com/Kilian/Trimage">GitHub</a>.</p>
<strong>Git:</strong> Trimage is primarily developed on <p><strong>Bzr:</strong> Trimage is also available on <a href="https://launchpad.net/trimage">Launchpad</a>.</p>
<a href="http://github.com/Kilian/Trimage">GitHub</a>.
</p>
<p>
<strong>Bzr:</strong> Trimage is also available on
<a href="https://launchpad.net/trimage">Launchpad</a>.
</p>
<p>Trimage is MIT licenced. We encourage contributions via GitHub.</p> <p>Trimage is MIT licenced. We encourage contributions via GitHub.</p>
</div> </div>
<div class="block"> <div class="block">
<h2>Thanks</h2> <h2>Thanks</h2>
<p>The following people helped develop Trimage:</p> <p>The following people helped develop Trimage:</p>
<ul> <ul>
<li><a href="https://hugo-posnic.fr/">Hugo Posnic</a></li>
<li>Neil Wallace</li> <li>Neil Wallace</li>
<li>Jeroen Goudsmit</li> <li>Jeroen Goudsmit</li>
<li>Tarnay Kálmán</li> <li>Tarnay Kálmán</li>
@ -178,11 +151,21 @@
<li>Kyrill Detinov</li> <li>Kyrill Detinov</li>
</ul> </ul>
</div> </div>
<div class="block">
<h2>Donate</h2>
<p>If you enjoy using Trimage, please buy us a coffee or a beer :)</p>
<a href='http://www.pledgie.com/campaigns/9607'><img alt='Click here to lend your support to: Trimage and make a donation at www.pledgie.com !' src='http://www.pledgie.com/campaigns/9607.png?skin_name=chrome' border='0' /></a>
<script type="text/javascript">
var flattr_url = 'http://trimage.org';
var flattr_btn='compact';
</script>
<script src="http://api.flattr.com/button/load.js" type="text/javascript"></script>
</div>
<div class="block"> <div class="block">
<h2>Requirements</h2> <h2>Requirements</h2>
<ul> <ul>
<li>python <em>3</em></li> <li>python <em>2.6</em></li>
<li>python-qt5 <em>5</em></li> <li>python-qt4 <em>4.4</em></li>
<li>optipng <em>0.6.2.1</em></li> <li>optipng <em>0.6.2.1</em></li>
<li>pngcrush <em>1.6.7</em></li> <li>pngcrush <em>1.6.7</em></li>
<li>advancecomp <em>1.15</em></li> <li>advancecomp <em>1.15</em></li>
@ -209,18 +192,28 @@
</div> </div>
<div class="block"> <div class="block">
<h2>Help</h2> <h2>Help</h2>
<p> <p>Please use <a href="http://github.com/Kilian/Trimage">GitHub</a> for reporting bugs and email <a href="mailto:help@trimage.org">help@trimage.org</a> for general questions (though we are not a helpdesk!)</p>
Please use <a href="https://github.com/Kilian/Trimage">GitHub</a> for
reporting bugs and email
<a href="mailto:help@trimage.org">help@trimage.org</a> for general
questions (though we are not a helpdesk!)
</p>
</div> </div>
<p class="footer">
Trimage is &copy; 2010&ndash;2019 <h2>Planned features</h2>
<a href="http://kilianvalkhof.com">Kilian Valkhof</a>, <p>Version 1.1.0 final:</p>
<a href="http://paulchaplin.com">Paul Chaplin</a> <ul>
</p> <li>Expand command line options</li>
<li>General refactoring</li>
</ul>
<p>Version 1.1.1 final:</p>
<ul>
<li>Use multiprocessing instead of threads</li>
</ul>
<p>Beyond that</p>
<ul>
<li>Deletion of rows in the table view</li>
<li>Integration with online services such as punypng</li>
<li><a href="mailto:help@trimage.org">Suggest something</a></li>
</ul>
<p class="footer">Trimage is &copy; 2010 <a href="http://kilianvalkhof.com">Kilian Valkhof</a>, <a href="http://paulchaplin.com">Paul Chaplin</a>
</div> </div>
</body> </body>
</html> </html>

BIN
website/mac.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 891 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 835 B

BIN
website/mandriva.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

BIN
website/opensuse.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
website/windows.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB