class ImageService
{
- protected static array $supportedExtensions = ['jpg', 'jpeg', 'png', 'gif', 'webp'];
+ protected static array $supportedExtensions = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'avif'];
public function __construct(
protected ImageStorage $storage,
UploadedFile $uploadedFile,
string $type,
int $uploadedTo = 0,
- int $resizeWidth = null,
- int $resizeHeight = null,
- bool $keepRatio = true
+ ?int $resizeWidth = null,
+ ?int $resizeHeight = null,
+ bool $keepRatio = true,
+ string $imageName = '',
): Image {
- $imageName = $uploadedFile->getClientOriginalName();
+ $imageName = $imageName ?: $uploadedFile->getClientOriginalName();
$imageData = file_get_contents($uploadedFile->getRealPath());
if ($resizeWidth !== null || $resizeHeight !== null) {
*/
public function destroy(Image $image): void
{
- $disk = $this->storage->getDisk($image->type);
- $disk->destroyAllMatchingNameFromPath($image->path);
+ $this->destroyFileAtPath($image->type, $image->path);
$image->delete();
}
+ /**
+ * Destroy the underlying image file at the given path.
+ */
+ public function destroyFileAtPath(string $type, string $path): void
+ {
+ $disk = $this->storage->getDisk($type);
+ $disk->destroyAllMatchingNameFromPath($path);
+ }
+
/**
* Delete gallery and drawings that are not within HTML content of pages or page revisions.
* Checks based off of only the image name.