提交 7b80717b 编写于 作者: W wizardforcel

update __init__

上级 72fd3ea6
......@@ -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"
......
......@@ -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)
......
......@@ -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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册