提交 918006c5 编写于 作者: W wizardforcel

优化编码器

上级 577bf64d
......@@ -7,4 +7,4 @@ https://github.com/apachecn/BiliDriveEx"""
__author__ = "ApacheCN"
__email__ = "apachecn@163.com"
__license__ = "SATA"
__version__ = "2019.01.22"
__version__ = "2019.03.06"
......@@ -50,14 +50,14 @@ class Encoder:
minsz = minw * minh * dep
if len(data) < minsz:
data = data + b'\0' * (minsz - len(data))
data += b'\0' * (minsz - len(data))
rem = len(data) % (minw * dep)
if rem != 0:
data = data + b'\0' * (minw * dep - rem)
hei = len(data) // (minw * dep)
side = math.ceil(math.sqrt(len(data) / dep))
total = side * side * dep
if len(data) < total:
data += b'\0' * (total - len(data))
img = Image.frombytes(mode, (minw, hei), data)
img = Image.frombytes(mode, (side, side), data)
bio = BytesIO()
img.save(bio, 'png')
return bio.getvalue()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册