That is a bridge of pngquant for python3
What's new 1.1.1
- add default pngquant sdk path in constructor
- verify pngquant sdk path
- https://pkgs.org/download/pngquant
- Ex: https://ubuntu.pkgs.org/20.04/ubuntu-universe-amd64/pngquant_2.12.2-1_amd64.deb.html
- This document will cover
git clone --recursive git://github.com/kornelski/pngquant.git
cd pngquant
make
sudo make install
which pngquant
$ /usr/local/bin/pngquant
pngquant --version
$ 2.17.0 (September 2021)
from smilepngquant.PNGQuant import PNGQuant
# initialize
smile = PNGQuant()
or
smile = PNGQuant('/usr/local/bin/pngquant')
*** by default the application located in /usr/local/bin/pngquant
*** it's able to set to another location via
smile.setPngQuant(path= '/home/winny/pngquant')
smile.compress(
filename = '/home/winny/Download/kara.png'
, quality = 80
)
if smile.isError():
print(f'Everything is okay, the file name is: {smile.getFilename()}')
else:
print(f'{smile.getErrorMessage()}')
-
dirname: can be None set coy to a new directory for the new file
-
newFilename: can be None set a new copy name
Both can set any value, or None, or one of them.
Let check the example:
Ex 1
smile.compress(
filename = '/home/winny/Download/kara.png'
, quality = 80
# move to new directory
, dirname = '/home/winny/Document/'
, newFilename = 'jojo'
)
Ex 2
smile.compress(
filename = '/home/winny/Download/kara.png'
, quality = 80
# move to new directory
, dirname = '/home/winny/Document/'
)
Ex 3
smile.compress(
filename = '/home/winny/Download/kara.png'
, quality = 80
# move to new directory
, newFilename = 'jojo'
)
It is also available on https://pypi.org/project/smilepngquant
To Support my work, please donate me via Buy me a Coffee