+
+ /**
+ * Get the regex pattern to identify image URLs.
+ * Caches the pattern since it requires looking up to settings/config.
+ */
+ protected function getUrlPattern(): string
+ {
+ if ($this->pattern) {
+ return $this->pattern;
+ }
+
+ $urls = [url('/uploads/images')];
+ $baseImageUrl = ImageStorage::getPublicUrl('/uploads/images');
+ if ($baseImageUrl !== $urls[0]) {
+ $urls[] = $baseImageUrl;
+ }
+
+ $imageUrlRegex = implode('|', array_map(fn ($url) => preg_quote($url, '/'), $urls));
+ $this->pattern = '/^(' . $imageUrlRegex . ')\/(.+)/';
+
+ return $this->pattern;
+ }