Merge pull request #394 from shenyanshu/Bot

修复实时便签绘制图片报错’百分比必须在0-1之间'的问题
This commit is contained in:
惜月 2023-02-27 15:36:13 +08:00 committed by GitHub
commit 2b86a6c108
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -380,8 +380,12 @@ class PMImage:
:param transparent: 是否透明
"""
if isinstance(percent, float):
if percent < 0 or percent > 1:
raise ValueError('百分比必须在0-1之间')
if percent < 0:
percent = -percent
if percent > 10:
raise ValueError('图片传入百分比错误')
if percent > 1 and percent < 10:
percent /= 10
percent = [percent, 1 - percent]
if isinstance(colors, str):
colors = [colors, '#FFFFFF']