mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
feat: process profile image
This commit is contained in:
parent
a295003ad4
commit
797a09f583
12 changed files with 207 additions and 104 deletions
39
torrent-client/profile_image_processor.py
Normal file
39
torrent-client/profile_image_processor.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
from PIL import Image
|
||||
import tempfile
|
||||
import os, uuid
|
||||
|
||||
class ProfileImageProcessor:
|
||||
|
||||
@staticmethod
|
||||
def get_parsed_image_data(image_path):
|
||||
Image.MAX_IMAGE_PIXELS = 933120000
|
||||
|
||||
image = Image.open(image_path)
|
||||
|
||||
try:
|
||||
image.seek(1)
|
||||
except EOFError:
|
||||
mime_type = image.get_format_mimetype()
|
||||
return image_path, mime_type
|
||||
else:
|
||||
newUUID = str(uuid.uuid4())
|
||||
new_image_path = os.path.join(tempfile.gettempdir(), newUUID) + ".webp"
|
||||
image.save(new_image_path)
|
||||
|
||||
new_image = Image.open(new_image_path)
|
||||
mime_type = new_image.get_format_mimetype()
|
||||
|
||||
return new_image_path, mime_type
|
||||
|
||||
|
||||
@staticmethod
|
||||
def process_image(image_path):
|
||||
return ProfileImageProcessor.get_parsed_image_data(image_path)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
result = ProfileImageProcessor.get_parsed_image_data("D:\Imagens\807b5c4b02e765bb4930b7c66662ef4b.gif")
|
||||
print(result)
|
||||
|
||||
result = ProfileImageProcessor.get_parsed_image_data("D:/Imagens/20240416_233352~2.png")
|
||||
print(result)
|
Loading…
Add table
Add a link
Reference in a new issue