diff --git a/app/Actions/Album/Archive.php b/app/Actions/Album/Archive.php index c51fd9a5c82..faf201d9f3d 100644 --- a/app/Actions/Album/Archive.php +++ b/app/Actions/Album/Archive.php @@ -180,7 +180,12 @@ private function compress_album($photos_sql, $dir_name, &$dirs, $parent_dir, $al $pos = strrpos($tmp_file, '.'); while (in_array($tmp_file, $files)) { // Set new title for photo - $tmp_file = substr_replace($file, '-' . $i, $pos, 0); + if ($pos !== false) { + $tmp_file = substr_replace($file, '-' . $i, $pos, 0); + } else { + // No extension. + $tmp_file = $file . '-' . $i; + } $i++; } $file = $tmp_file; diff --git a/app/Actions/Photo/Extensions/ImageEditing.php b/app/Actions/Photo/Extensions/ImageEditing.php index 3f3fb59e75d..b880dcf1d32 100644 --- a/app/Actions/Photo/Extensions/ImageEditing.php +++ b/app/Actions/Photo/Extensions/ImageEditing.php @@ -129,7 +129,7 @@ public function resizePhoto(Photo $photo, string $type, int $maxWidth, int $maxH // Add the @2x postfix if we're dealing with an HiDPI type if (strpos($type, '2x') > 0) { - $filename = preg_replace('/^(.*)\.(.*)$/', '\1@2x.\2', $filename); + $filename = Helpers::ex2x($filename); } // Is photo big enough? diff --git a/app/Assets/Helpers.php b/app/Assets/Helpers.php index 3f2a4bbff28..d6e01990af3 100644 --- a/app/Assets/Helpers.php +++ b/app/Assets/Helpers.php @@ -206,7 +206,9 @@ public static function ex2x($url) { $thumbUrl2x = explode('.', $url); - return $thumbUrl2x[0] . '@2x.' . $thumbUrl2x[1]; + return (count($thumbUrl2x) === 2) ? + $thumbUrl2x[0] . '@2x.' . $thumbUrl2x[1] : + $thumbUrl2x[0] . '@2x'; } /** diff --git a/app/Console/Commands/Ghostbuster.php b/app/Console/Commands/Ghostbuster.php index 3700958f5dc..4ef03d8234f 100644 --- a/app/Console/Commands/Ghostbuster.php +++ b/app/Console/Commands/Ghostbuster.php @@ -2,6 +2,7 @@ namespace App\Console\Commands; +use App\Assets\Helpers; use App\Console\Commands\Utilities\Colorize; use App\Models\Photo; use Illuminate\Console\Command; @@ -93,9 +94,9 @@ public function handle() // for normal pictures $to_delete[] = 'small/' . $url; - $to_delete[] = 'small/' . $photoName[0] . '@2x.' . $photoName[1]; + $to_delete[] = 'small/' . Helpers::ex2x($url); $to_delete[] = 'medium/' . $url; - $to_delete[] = 'medium/' . $photoName[0] . '@2x.' . $photoName[1]; + $to_delete[] = 'medium/' . Helpers::ex2x($url); $to_delete[] = 'big/' . $url; foreach ($to_delete as $del) { diff --git a/app/Models/Photo.php b/app/Models/Photo.php index 12dfb733089..951f2d70da7 100644 --- a/app/Models/Photo.php +++ b/app/Models/Photo.php @@ -4,6 +4,7 @@ namespace App\Models; +use App\Assets\Helpers; use App\Models\Extensions\PhotoBooleans; use App\Models\Extensions\PhotoCast; use App\Models\Extensions\PhotoGetters; @@ -185,8 +186,7 @@ public function predelete(bool $keep_original = false) $photoName = $this->url; } if ($photoName !== '') { - $photoName2x = explode('.', $photoName); - $photoName2x = $photoName2x[0] . '@2x.' . $photoName2x[1]; + $photoName2x = Helpers::ex2x($photoName); // Delete Live Photo Video file // TODO: USE STORAGE FOR DELETE @@ -230,8 +230,7 @@ public function predelete(bool $keep_original = false) if ($this->thumbUrl != '') { // Get retina thumb url - $thumbUrl2x = explode('.', $this->thumbUrl); - $thumbUrl2x = $thumbUrl2x[0] . '@2x.' . $thumbUrl2x[1]; + $thumbUrl2x = Helpers::ex2x($this->thumbUrl); // Delete thumb // TODO: USE STORAGE FOR DELETE if (Storage::exists('thumb/' . $this->thumbUrl) && !unlink(Storage::path('thumb/' . $this->thumbUrl))) {