ESN-Trondheim / ESNbot

A Slack bot for ESN Trondheim
MIT License
3 stars 1 forks source link

Look at MIME type when using watermark/coverphoto, not just extension #54

Open LaiAlexander opened 10 months ago

LaiAlexander commented 10 months ago

If the supplied picture has a different MIME type than what the extension is, this may cause issues/crashes.

Traceback (most recent call last):
File "/home/lai/.local/lib/python3.8/site-packages/PIL/[JpegImagePlugin.py](http://jpegimageplugin.py/)", line 619, in _save
rawmode = RAWMODE[im.mode]
KeyError: 'RGBA'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "[esnbot.py](http://esnbot.py/)", line 608, in <module>
run()
File "[esnbot.py](http://esnbot.py/)", line 602, in run
handle_command(text, channel, user, output)
File "[esnbot.py](http://esnbot.py/)", line 205, in handle_command
choose_command(command, arguments, channel, user, output)
File "[esnbot.py](http://esnbot.py/)", line 228, in choose_command
return func(channel, arguments, user, output)
File "[esnbot.py](http://esnbot.py/)", line 469, in command_watermark
wm.watermark(start_img, argument, filename)
File "/home/lai/ESNbot/[watermark.py](http://watermark.py/)", line 130, in watermark
start_img.save(filename)
File "/home/lai/.local/lib/python3.8/site-packages/PIL/[Image.py](http://image.py/)", line 2084, in save
save_handler(self, fp, filename)
File "/home/lai/.local/lib/python3.8/site-packages/PIL/[JpegImagePlugin.py](http://jpegimageplugin.py/)", line 621, in _save
raise IOError("cannot write mode %s as JPEG" % im.mode)
OSError: cannot write mode RGBA as JPEG

image