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))
python类add()的实例源码
def trim(im):
bg = Image.new(im.mode, im.size, im.getpixel((0, 0)))
diff = ImageChops.difference(im, bg)
diff = ImageChops.add(diff, diff, 2.0, -100)
bbox = diff.getbbox()
if bbox:
return im.crop(bbox)
def trim(im):
bg = Image.new(im.mode, im.size, im.getpixel((0, 0)))
diff = ImageChops.difference(im, bg)
diff = ImageChops.add(diff, diff, 2.0, -100)
bbox = diff.getbbox()
if bbox:
return im.crop(bbox)
else:
return im
def setup():
config.add(api_key)
config.add(page_load_timeout)
if not api_key():
raise PluginSetupError("This plugin requires an API key to be chosen.")
app.add(handle)
def trim_whitespace(im):
bg = Image.new(im.mode, im.size, im.getpixel((0, 0)))
diff = ImageChops.difference(im, bg)
diff = ImageChops.add(diff, diff, 2.0, -100)
bbox = diff.getbbox()
if bbox:
return im.crop(bbox)
def setup():
commands.add(pie)
commands.add(bar)
commands.add(histogram)
commands.add(latex)
def trim(self, im):
"""
Auto-trim
"""
bg = Image.new(im.mode, im.size, im.getpixel((0, 0)))
diff = ImageChops.difference(im, bg)
diff = ImageChops.add(diff, diff, 2.0, -100)
bbox = diff.getbbox()
if bbox:
return im.crop(bbox)
def trim(im):
pixel = (255, 255, 255) # ????????????? ?? ????? ????
# pixel = im.getpixel((0,0)) # ????????????? ?? ??????? ? ?????? ???????? ????
bg = Image.new(im.mode, im.size, pixel)
diff = ImageChops.difference(im, bg)
diff = ImageChops.add(diff, diff, 2.0, -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")])