def ocr(self, ctx):
"""OCR an image.
Usage: ocr [attach an image]"""
or_check_perms(ctx, ('bot_owner',))
warnings.simplefilter('error', Image.DecompressionBombWarning)
if ctx.message.attachments:
with async_timeout.timeout(5):
async with self.bot.cog_http.get(ctx.message.attachments[0].proxy_url) as r:
raw_image = await r.read()
else:
await ctx.send(':warning: No attachment found.')
return
img_bytes = BytesIO(raw_image)
image = Image.open(img_bytes)
text = tesserocr.image_to_text(image)
if text:
await ctx.send(text)
else:
await ctx.send('No results.')
评论列表
文章目录