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")
|
@bot.listen("on_message")
|
||||||
async def convert_heic_to_jpg(ctx):
|
async def convert_heic_to_jpg(ctx):
|
||||||
from cmagick import cmagick
|
from cmagick import cmagick
|
||||||
|
import time
|
||||||
|
import tempfile
|
||||||
|
|
||||||
if ctx.attachments:
|
if ctx.attachments:
|
||||||
for attachment in ctx.attachments:
|
for attachment in ctx.attachments:
|
||||||
if attachment.filename.lower().endswith(("heic", "tiff")):
|
if attachment.filename.lower().endswith(("heic", "tiff")):
|
||||||
source_file = "/tmp/source"
|
source_file = "/tmp/source"
|
||||||
jpg_file = "/tmp/converted.jpg"
|
source_file, file_path = tempfile.mkstemp()
|
||||||
await attachment.save(fp=source_file)
|
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:
|
try:
|
||||||
await ctx.delete()
|
await ctx.delete()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user