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

优化编码器

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