From 5b6a334dd0252addd026136e313bc5c3d3d2e48d Mon Sep 17 00:00:00 2001 From: Alex Cabal Date: Mon, 8 Jan 2024 13:48:56 -0600 Subject: [PATCH] Add minimum artwork dimensions --- lib/Artwork.php | 8 +++++++- lib/Constants.php | 2 ++ .../ArtworkImageDimensionsTooSmallException.php | 11 +++++++++++ www/artworks/new.php | 2 +- 4 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 lib/Exceptions/ArtworkImageDimensionsTooSmallException.php diff --git a/lib/Artwork.php b/lib/Artwork.php index 9ec163e3..c1672ebf 100644 --- a/lib/Artwork.php +++ b/lib/Artwork.php @@ -365,7 +365,13 @@ class Artwork extends PropertiesBase{ } if(!is_uploaded_file($uploadedFile['tmp_name'])){ - throw new Exceptions\InvalidImageUploadException(); + $error->Add(new Exceptions\InvalidImageUploadException()); + } + + // Check for minimum dimensions + list($imageWidth, $imageHeight) = getimagesize($uploadedFile['tmp_name']); + if(!$imageWidth || !$imageHeight || $imageWidth < COVER_ARTWORK_IMAGE_MINIMUM_WIDTH || $imageHeight < COVER_ARTWORK_IMAGE_MINIMUM_HEIGHT){ + $error->Add(new Exceptions\ArtworkImageDimensionsTooSmallException()); } } diff --git a/lib/Constants.php b/lib/Constants.php index a4f2bafa..88e91425 100644 --- a/lib/Constants.php +++ b/lib/Constants.php @@ -44,6 +44,8 @@ const COVER_ARTWORK_STATUS_IN_USE = 'in_use'; const COVER_ARTWORK_STATUS_UNVERIFIED = 'unverified'; const COVER_ARTWORK_MAX_STRING_LENGTH = 191; const COVER_ARTWORK_MAX_TAGS = 100; +const COVER_ARTWORK_IMAGE_MINIMUM_WIDTH = 300; +const COVER_ARTWORK_IMAGE_MINIMUM_HEIGHT = 300; const SORT_COVER_ARTWORK_CREATED_NEWEST = 'created-newest'; const SORT_COVER_ARTIST_ALPHA = 'artist-alpha'; const SORT_COVER_ARTWORK_COMPLETED_NEWEST = 'completed-newest'; diff --git a/lib/Exceptions/ArtworkImageDimensionsTooSmallException.php b/lib/Exceptions/ArtworkImageDimensionsTooSmallException.php new file mode 100644 index 00000000..3dae3f4c --- /dev/null +++ b/lib/Exceptions/ArtworkImageDimensionsTooSmallException.php @@ -0,0 +1,11 @@ +message = 'Image dimensions are too small. The minimum image size is ' . number_format(COVER_ARTWORK_IMAGE_MINIMUM_WIDTH) . ' × ' . number_format(COVER_ARTWORK_IMAGE_MINIMUM_HEIGHT) . '.'; + } +} diff --git a/www/artworks/new.php b/www/artworks/new.php index efe214c7..7c38bc93 100644 --- a/www/artworks/new.php +++ b/www/artworks/new.php @@ -137,7 +137,7 @@ catch(Exceptions\InvalidPermissionsException){