(sorta) Fixed images

This commit is contained in:
some weird guy
2023-07-24 21:20:53 -07:00
parent c02fed1eb3
commit 7ad2003b2c
+2 -5
View File
@@ -81,8 +81,8 @@ def recaptcha_verify(request, key):
return True return True
ImageFile.LOAD_TRUNCATED_IMAGES = True ImageFile.LOAD_TRUNCATED_IMAGES = True
# This image upload code is fucked now thanks to pillow. I gotta go through it and refine it.
def image_upload(img, stream=False, drawing=False): def image_upload(img, stream=False, drawing=False):
try:
# Decode the image # Decode the image
decodedimg = img.read() if stream else base64.b64decode(img) decodedimg = img.read() if stream else base64.b64decode(img)
# Open the image # Open the image
@@ -101,7 +101,7 @@ def image_upload(img, stream=False, drawing=False):
if orientation in rotations: if orientation in rotations:
im = im.transpose(rotations[orientation]) im = im.transpose(rotations[orientation])
# Resize the image # Resize the image
im.thumbnail((800, 800), Image.ANTIALIAS) im.thumbnail((800, 800))
# Check the aspect ratio if this is a drawing # Check the aspect ratio if this is a drawing
if drawing and ((im.size[0] / im.size[1]) < 0.30): if drawing and ((im.size[0] / im.size[1]) < 0.30):
return 1 return 1
@@ -115,9 +115,6 @@ def image_upload(img, stream=False, drawing=False):
im.save(settings.MEDIA_ROOT + floc, target, quality=80, method=6) im.save(settings.MEDIA_ROOT + floc, target, quality=80, method=6)
# Return the URL of the file # Return the URL of the file
return settings.MEDIA_URL + floc return settings.MEDIA_URL + floc
# Catch any errors
except (OSError, SyntaxError, ValueError):
return 1
# Todo: Put this into post/comment delete thingy method # Todo: Put this into post/comment delete thingy method
def image_rm(image_url): def image_rm(image_url):