convert heic to jpg and reupload the imgage

This commit is contained in:
Luke Robles 2021-09-09 11:20:41 -07:00
parent d282263348
commit 7d0604dc9c
4 changed files with 23 additions and 3 deletions

View File

@ -1,8 +1,9 @@
FROM python:3.8 as build
ADD app/requirements.txt /requirements.txt
RUN pip install -r requirements.txt
RUN apt-get update && apt-get install -y libmagickwand-dev && pip install -r requirements.txt
FROM python:3.8-slim
RUN apt-get update && apt-get install -y libmagickwand-dev
COPY --from=0 /usr/local/lib/python3.8/site-packages /usr/local/lib/python3.8/site-packages
ADD app /app
CMD python /app/bot.py
WORKDIR /app

View File

@ -1,8 +1,9 @@
FROM python:3.8 as build
ADD app/requirements.txt /requirements.txt
RUN pip install -r requirements.txt
RUN apt-get update && apt-get install -y libmagickwand-dev && pip install -r requirements.txt
FROM python:3.8-slim
RUN apt-get update && apt-get install -y libmagickwand-dev
COPY --from=0 /usr/local/lib/python3.8/site-packages /usr/local/lib/python3.8/site-packages
ADD app /app
WORKDIR /app

View File

@ -55,7 +55,24 @@ async def react_with_dale(ctx):
await ctx.add_reaction(emoji)
return
@bot.listen('on_message')
async def convert_heic_to_jpg(ctx):
from wand.image import Image
if ctx.attachments:
for attachment in ctx.attachments:
if attachment.filename.lower().endswith('heic'):
heic_file = '/tmp/heic'
jpg_file = '/tmp/jpg.jpg'
await attachment.save(fp=heic_file)
# Convert heic to jpg
img=Image(filename=heic_file)
img.format='jpg'
img.save(filename=jpg_file)
img.close()
await ctx.delete()
await ctx.channel.send(file=discord.File(jpg_file))
return
@bot.event

View File

@ -7,3 +7,4 @@ requests
owotext
wikipedia
wolframalpha
Wand