diff --git a/app/Services/FileManagerService.php b/app/Services/FileManagerService.php index f6441dda..87cfa4e6 100644 --- a/app/Services/FileManagerService.php +++ b/app/Services/FileManagerService.php @@ -419,7 +419,7 @@ class FileManagerService $this->helper->check_user_storage_capacity($user_id, $file_size, $temp_filename); // Create thumbnail - $thumbnail = self::get_image_thumbnail('chunks/' . $temp_filename, $disk_file_name, $user_id); + $thumbnail = $this->helper->get_image_thumbnail('chunks/' . $temp_filename, $disk_file_name, $user_id); // Move finished file from chunk to file-manager directory $disk_local->move('chunks/' . $temp_filename, "files/$user_id/$disk_file_name"); @@ -486,44 +486,4 @@ class FileManagerService ]); } } - - /** - * Create thumbnail for images - * - * @param string $file_path - * @param string $filename - * @param string $user_id - * @param $file - * @return string|null - */ - private function get_image_thumbnail(string $file_path, string $filename, string $user_id) - { - $local_disk = Storage::disk('local'); - - // Create thumbnail from image - if (in_array($local_disk->mimeType($file_path), ['image/gif', 'image/jpeg', 'image/jpg', 'image/png', 'image/webp'])) { - - // Get thumbnail name - $thumbnail = 'thumbnail-' . $filename; - - // Create intervention image - $image = Image::make($local_disk->path($file_path))->orientate(); - - // Resize image - $image->resize(512, null, function ($constraint) { - $constraint->aspectRatio(); - })->stream(); - - // Store thumbnail to disk - $local_disk->put("files/$user_id/$thumbnail", $image); - } - - // Return thumbnail as svg file - if ($local_disk->mimeType($file_path) === 'image/svg+xml') { - - $thumbnail = $filename; - } - - return $thumbnail ?? null; - } } \ No newline at end of file diff --git a/app/Services/HelperService.php b/app/Services/HelperService.php index 3ce8c462..df1bfa50 100644 --- a/app/Services/HelperService.php +++ b/app/Services/HelperService.php @@ -9,6 +9,7 @@ use DB; use Illuminate\Support\Arr; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Storage; +use Intervention\Image\ImageManagerStatic as Image; use Symfony\Component\HttpKernel\Exception\HttpException; class HelperService @@ -99,7 +100,7 @@ class HelperService * @param string $filename * @param string|null $thumbnail */ - function move_to_external_storage(string $filename, ?string $thumbnail): void + function move_to_external_storage($filename, $thumbnail = null): void { $disk_local = Storage::disk('local'); @@ -157,4 +158,44 @@ class HelperService $disk_local->delete('files/' . $file); } } + + /** + * Create image thumbnail from gif, jpeg, jpg, png, webp or svg + * + * @param string $file_path + * @param string $filename + * @param string $user_id + * @return string|null + */ + function get_image_thumbnail($file_path, $filename, $user_id) + { + $local_disk = Storage::disk('local'); + + // Create thumbnail from image + if (in_array($local_disk->mimeType($file_path), ['image/gif', 'image/jpeg', 'image/jpg', 'image/png', 'image/webp'])) { + + // Get thumbnail name + $thumbnail = "thumbnail-$filename"; + + // Create intervention image + $image = Image::make($local_disk->path($file_path)) + ->orientate(); + + // Resize image + $image->resize(512, null, function ($constraint) { + $constraint->aspectRatio(); + })->stream(); + + // Store thumbnail to disk + $local_disk->put("files/$user_id/$thumbnail", $image); + } + + // Return thumbnail as svg file + if ($local_disk->mimeType($file_path) === 'image/svg+xml') { + + $thumbnail = $filename; + } + + return $thumbnail ?? null; + } } \ No newline at end of file