Fixing the image conversion to use temp files and time.time for filename on upload
This commit is contained in:
parent
8fec94142f
commit
a6c4e8c5a2
9
app/bot.py
Executable file → Normal file
9
app/bot.py
Executable file → Normal file
@ -53,15 +53,18 @@ async def fix_cdn_url(ctx):
|
||||
@bot.listen("on_message")
|
||||
async def convert_heic_to_jpg(ctx):
|
||||
from cmagick import cmagick
|
||||
import time
|
||||
import tempfile
|
||||
|
||||
if ctx.attachments:
|
||||
for attachment in ctx.attachments:
|
||||
if attachment.filename.lower().endswith(("heic", "tiff")):
|
||||
source_file = "/tmp/source"
|
||||
jpg_file = "/tmp/converted.jpg"
|
||||
await attachment.save(fp=source_file)
|
||||
source_file, file_path = tempfile.mkstemp()
|
||||
jpg_file = "/tmp/%s.jpg" % time.time()
|
||||
await attachment.save(fp=file_path)
|
||||
|
||||
img = cmagick.convert(source_file, jpg_file)
|
||||
img = cmagick.convert(file_path, jpg_file)
|
||||
|
||||
try:
|
||||
await ctx.delete()
|
||||
|
Loading…
x
Reference in New Issue
Block a user