This commit is contained in:
Bryan Gerlach
2025-02-24 12:22:03 -06:00
parent 80fc9f6a84
commit ca0d321873

View File

@@ -82,23 +82,24 @@ class GenerateForm(forms.Form):
def clean_iconfile(self): def clean_iconfile(self):
print("checking icon") print("checking icon")
image = self.cleaned_data['iconfile'] image = self.cleaned_data['iconfile']
try: if image:
# Open the image using Pillow try:
img = Image.open(image) # Open the image using Pillow
img = Image.open(image)
# Check if the image is a PNG (optional, but good practice) # Check if the image is a PNG (optional, but good practice)
if img.format != 'PNG': if img.format != 'PNG':
raise forms.ValidationError("Only PNG images are allowed.") raise forms.ValidationError("Only PNG images are allowed.")
# Get image dimensions # Get image dimensions
width, height = img.size width, height = img.size
# Check for square dimensions # Check for square dimensions
if width != height: if width != height:
raise forms.ValidationError("Custom App Icon dimensions must be square.") raise forms.ValidationError("Custom App Icon dimensions must be square.")
return image return image
except OSError: # Handle cases where the uploaded file is not a valid image except OSError: # Handle cases where the uploaded file is not a valid image
raise forms.ValidationError("Invalid icon file.") raise forms.ValidationError("Invalid icon file.")
except Exception as e: # Catch any other image processing errors except Exception as e: # Catch any other image processing errors
raise forms.ValidationError(f"Error processing icon: {e}") raise forms.ValidationError(f"Error processing icon: {e}")