mirror of
https://github.com/bryangerlach/rdgen.git
synced 2025-12-02 18:13:16 +00:00
force icon dimensions to be square
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from django import forms
|
||||
from PIL import Image
|
||||
|
||||
class GenerateForm(forms.Form):
|
||||
#Platform
|
||||
@@ -76,4 +77,28 @@ class GenerateForm(forms.Form):
|
||||
xOffline = forms.BooleanField(initial=False, required=False)
|
||||
hidecm = forms.BooleanField(initial=False, required=False)
|
||||
statussort = forms.BooleanField(initial=False, required=False)
|
||||
removeNewVersionNotif = forms.BooleanField(initial=False, required=False)
|
||||
removeNewVersionNotif = forms.BooleanField(initial=False, required=False)
|
||||
|
||||
def clean_iconfile(self):
|
||||
print("checking icon")
|
||||
image = self.cleaned_data['iconfile']
|
||||
try:
|
||||
# Open the image using Pillow
|
||||
img = Image.open(image)
|
||||
|
||||
# Check if the image is a PNG (optional, but good practice)
|
||||
if img.format != 'PNG':
|
||||
raise forms.ValidationError("Only PNG images are allowed.")
|
||||
|
||||
# Get image dimensions
|
||||
width, height = img.size
|
||||
|
||||
# Check for square dimensions
|
||||
if width != height:
|
||||
raise forms.ValidationError("Custom App Icon dimensions must be square.")
|
||||
|
||||
return image
|
||||
except OSError: # Handle cases where the uploaded file is not a valid image
|
||||
raise forms.ValidationError("Invalid icon file.")
|
||||
except Exception as e: # Catch any other image processing errors
|
||||
raise forms.ValidationError(f"Error processing icon: {e}")
|
||||
Reference in New Issue
Block a user