Python PIL.ImageChops 模块,add() 实例源码
我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用PIL.ImageChops.add()。
def do_add(self):
"""usage: add <image:pic1> <image:pic2> <int:offset> <float:scale>
Pop the two top images,produce the scaled sum with offset.
"""
from PIL import ImageChops
image1 = self.do_pop()
image2 = self.do_pop()
scale = float(self.do_pop())
offset = int(self.do_pop())
self.push(ImageChops.add(image1, image2, scale, offset))
def setup():
commands.add(pie)
commands.add(bar)
commands.add(histogram)
commands.add(latex)
def trim(im):
pixel = (255, 255, 255) # ????????????? ?? ????? ????
# pixel = im.getpixel((0,0)) # ????????????? ?? ??????? ? ?????? ???????? ????
bg = Image.new(im.mode, pixel)
diff = ImageChops.difference(im, -100)
bBox = diff.getbBox()
logger.info(bBox)
if bBox:
return im.crop(bBox)
else:
return im
def pie(message):
"""
Generate a pie graph. To specify the parts of the pie,make a
list separated by new lines,semi-colons or commas where each
list entry has a percentage in it (if there is more than one,the
first percentage is used).
To specify a graph title,don't provide a percentage for one of the
list items.
Example::
/pie Materials,40% Glass,22%
The percentages do not need to add up to 100%. If they do not,then
the percentage values will be normalized so that they do add up to 100%.
"""
title, labels, data = extract_data(message.content, pattern=PERCENTAGE_PATTERN, normalize=True)
def execute():
with lock:
plt.figure(1, figsize=(5, 5))
ax = plt.axes([0.1, 0.1, 0.4, 0.4])
plt.pie(data, labels=labels, autopct='%1.0f%%', startangle=90)
if title:
plt.title(title)
prop = fm.FontProperties(fname=font_path, size=11)
for text in ax.texts:
text.set_fontproperties(prop)
buf = io.BytesIO()
plt.savefig(buf, bBox_inches='tight', transparent=False, pad_inches=0.1)
plt.clf()
return buf
buf = await asyncio.get_event_loop().run_in_executor(None, execute)
return Response("", attachments=[MemoryAttachment(buf, "graph.png", "image/png")])
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。