@@ -82,23 +82,24 @@ class GenerateForm(forms.Form):
82
82
def clean_iconfile (self ):
83
83
print ("checking icon" )
84
84
image = self .cleaned_data ['iconfile' ]
85
- try :
86
- # Open the image using Pillow
87
- img = Image .open (image )
85
+ if image :
86
+ try :
87
+ # Open the image using Pillow
88
+ img = Image .open (image )
88
89
89
- # Check if the image is a PNG (optional, but good practice)
90
- if img .format != 'PNG' :
91
- raise forms .ValidationError ("Only PNG images are allowed." )
90
+ # Check if the image is a PNG (optional, but good practice)
91
+ if img .format != 'PNG' :
92
+ raise forms .ValidationError ("Only PNG images are allowed." )
92
93
93
- # Get image dimensions
94
- width , height = img .size
94
+ # Get image dimensions
95
+ width , height = img .size
95
96
96
- # Check for square dimensions
97
- if width != height :
98
- raise forms .ValidationError ("Custom App Icon dimensions must be square." )
99
-
100
- return image
101
- except OSError : # Handle cases where the uploaded file is not a valid image
102
- raise forms .ValidationError ("Invalid icon file." )
103
- except Exception as e : # Catch any other image processing errors
104
- raise forms .ValidationError (f"Error processing icon: { e } " )
97
+ # Check for square dimensions
98
+ if width != height :
99
+ raise forms .ValidationError ("Custom App Icon dimensions must be square." )
100
+
101
+ return image
102
+ except OSError : # Handle cases where the uploaded file is not a valid image
103
+ raise forms .ValidationError ("Invalid icon file." )
104
+ except Exception as e : # Catch any other image processing errors
105
+ raise forms .ValidationError (f"Error processing icon: { e } " )
0 commit comments