From 7b80717b5e9b77d351d38ca2c58e33295b0b4094 Mon Sep 17 00:00:00 2001 From: wizardforcel <562826179@qq.com> Date: Wed, 29 Apr 2020 18:41:16 +0800 Subject: [PATCH] update __init__ --- imgyaso/__init__.py | 6 ++++++ imgyaso/__main__.py | 4 ++-- imgyaso/quant.py | 7 ++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/imgyaso/__init__.py b/imgyaso/__init__.py index 6c6bbae..6c306bb 100644 --- a/imgyaso/__init__.py +++ b/imgyaso/__init__.py @@ -3,6 +3,12 @@ """ImgYaso https://github.com/apachecn/imgyaso""" +from .adathres import adathres_bts, adathres +from .dither import grid_bts, grid, noise_bts, noise +from .quant import pngquant_bts, pngquant +from .trunc import trunc_bts, trunc +from .util import * + __author__ = "ApacheCN" __email__ = "apachecn@163.com" __license__ = "SATA" diff --git a/imgyaso/__main__.py b/imgyaso/__main__.py index f7d5015..dc57783 100644 --- a/imgyaso/__main__.py +++ b/imgyaso/__main__.py @@ -3,7 +3,7 @@ from os import path from . import __version__ from .adathres import adathres_bts from .dither import grid_bts, noise_bts -from .quant import pngquant +from .quant import pngquant_bts from .trunc import trunc_bts from .util import * @@ -34,7 +34,7 @@ def main(): elif args.mode == 'trunc': img = trunc_bts(img, args.colors) elif args.mode == 'quant': - img = pngquant(img, args.colors) + img = pngquant_bts(img, args.colors) elif args.mode == 'thres': img = adathres_bts(img) diff --git a/imgyaso/quant.py b/imgyaso/quant.py index c128016..ee77961 100644 --- a/imgyaso/quant.py +++ b/imgyaso/quant.py @@ -7,6 +7,11 @@ import sys from .util import * def pngquant(img, ncolors=8): + img = bytes(cv2.imencode('.png', img, [cv2.IMWRITE_PNG_COMPRESSION, 9])[1]) + img = pngquant_bts(img, ncolors) + return cv2.imdecode(np.frombuffer(img, np.uint8), cv2.IMREAD_UNCHANGED) + +def pngquant_bts(img, ncolors=8): img = conv2png(img) fname = path.join( tempfile.gettempdir(), @@ -27,7 +32,7 @@ def pngquant(img, ncolors=8): def main(): fname = sys.argv[1] img = open(fname, 'rb').read() - img = pngquant(img) + img = pngquant_bts(img) with open(fname, 'wb') as f: f.write(img) -- GitLab