Added a method to convert images to jpeg
This commit is contained in:
parent
91ff56f621
commit
a124eaf89a
|
@ -1,8 +1,20 @@
|
|||
import aiohttp
|
||||
import io
|
||||
from io import BytesIO
|
||||
import inspect
|
||||
|
||||
from . import config
|
||||
from PIL import Image
|
||||
|
||||
def convert_to_jpeg(pfile):
|
||||
# Open the file given
|
||||
img = Image.open(pfile)
|
||||
# Create the BytesIO object we'll use as our new "file"
|
||||
new_file = BytesIO()
|
||||
# Save to this file as jpeg
|
||||
img.save(new_file, format='JPEG')
|
||||
# In order to use the file, we need to seek back to the 0th position
|
||||
new_file.seek(0)
|
||||
return new_file
|
||||
|
||||
def get_all_commands(bot):
|
||||
"""Returns a list of all command names for the bot"""
|
||||
|
@ -61,7 +73,7 @@ async def download_image(url):
|
|||
return None
|
||||
|
||||
# Then wrap it in a BytesIO object, to be used like an actual file
|
||||
image = io.BytesIO(bts)
|
||||
image = BytesIO(bts)
|
||||
return image
|
||||
|
||||
async def request(url, *, headers=None, payload=None, method='GET', attr='json'):
|
||||
|
|
Loading…
Reference in a new issue