storage and image model
This commit is contained in:
+17
-25
@@ -2,12 +2,12 @@
|
||||
|
||||
namespace Lucent\File;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Contracts\Filesystem\Filesystem;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Log\Logger;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Intervention\Image\ImageManagerStatic;
|
||||
use Intervention\Image\ImageManager;
|
||||
use Lucent\Channel\ChannelService;
|
||||
use Lucent\Database\Database;
|
||||
use Lucent\LucentException;
|
||||
@@ -21,7 +21,9 @@ class FileService
|
||||
{
|
||||
|
||||
public function __construct(
|
||||
public ChannelService $channelService
|
||||
public ChannelService $channelService,
|
||||
public ImageManager $imageManager,
|
||||
public Logger $logger
|
||||
)
|
||||
{
|
||||
}
|
||||
@@ -65,7 +67,6 @@ class FileService
|
||||
isDuplicate: true
|
||||
);
|
||||
}
|
||||
|
||||
$disk = $this->loadDisk($schema);
|
||||
$path = $schema->path . "/" . $filename;
|
||||
$res = $disk->put(
|
||||
@@ -78,7 +79,8 @@ class FileService
|
||||
throw new LucentException("File $filename not uploaded");
|
||||
}
|
||||
|
||||
$this->createThumbnail($disk, $schema->path, $filename, $file);
|
||||
// $this->createThumbnail($disk, $schema->path, $filename, $file);
|
||||
$this->createTemplates($disk, $path, $file);
|
||||
|
||||
list($width, $height) = $this->isImage($mimetype) ? getimagesize($file) : [0, 0];
|
||||
$recordFile = new RecordFile(
|
||||
@@ -128,29 +130,19 @@ class FileService
|
||||
return $record->id ?? "";
|
||||
}
|
||||
|
||||
private function createThumbnail(Filesystem $disk, string $schemaPath, string $filename, UploadedFile $file): void
|
||||
private function createTemplates(Filesystem $disk, string $path, UploadedFile $file): void
|
||||
{
|
||||
$thumbDir = "thumbs/" . $schemaPath . "/";
|
||||
// if (!file_exists($thumbDir)) {
|
||||
// make_dir_r($thumbDir);
|
||||
// }
|
||||
|
||||
try {
|
||||
ImageManagerStatic::configure(['driver' => 'imagick']);
|
||||
$image = ImageManagerStatic::make($file);
|
||||
} catch (Exception $e) {
|
||||
logger($e->getMessage());
|
||||
return;
|
||||
$originalImage = $this->imageManager->make($disk->get($path));
|
||||
foreach (config("lucent.imageFilters") as $preset => $filterClass) {
|
||||
$image = $originalImage->filter(new $filterClass);
|
||||
$templateUri = "/templates/" . $preset . "/" . $path;
|
||||
$disk->put($templateUri, $image->encode('webp', 75));
|
||||
}
|
||||
|
||||
$image->fit(300, 300);
|
||||
try {
|
||||
$disk->put($thumbDir . $filename, $image->encode('webp', 75));
|
||||
// $image->encode('webp', 75)->save($thumbDir . $filename);
|
||||
} catch (Exception $e) {
|
||||
logger($e->getMessage());
|
||||
}
|
||||
$thumbDir = "thumbs/" . $path;
|
||||
|
||||
$image = $originalImage->fit(300, 300);
|
||||
$disk->put($thumbDir, $image->encode('webp', 75));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user