Commit d7c34dd2 authored by Nicolas Widart's avatar Nicolas Widart

Create all possible thumbs on upload

parent e0b8c32f
......@@ -60,6 +60,19 @@ class Imagy
return '/assets/media/' . $this->newFilename($originalImage, $thumbnail);
}
public function createAll($path)
{
foreach ($this->manager->all() as $thumbName => $filters) {
$image = $this->image->make(public_path() . $path);
$filename = '/assets/media/' . $this->newFilename($path, $thumbName);
foreach ($filters as $manipulation => $options) {
$image = $this->imageFactory->make($manipulation)->handle($image, $options);
}
$image = $image->encode(pathinfo($path, PATHINFO_EXTENSION));
$this->writeImage($filename, $image);
}
}
/**
* Prepend the thumbnail name to filename
* @param $path
......
<?php namespace Modules\Media\Services;
use Modules\Media\Image\Imagy;
use Modules\Media\Repositories\FileRepository;
use Symfony\Component\HttpFoundation\File\UploadedFile;
......@@ -9,10 +10,15 @@ class FileService
* @var FileRepository
*/
private $file;
/**
* @var Imagy
*/
private $imagy;
public function __construct(FileRepository $file)
public function __construct(FileRepository $file, Imagy $imagy)
{
$this->file = $file;
$this->imagy = $imagy;
}
public function store(UploadedFile $file)
......@@ -24,6 +30,7 @@ class FileService
$file->move(public_path() . '/assets/media', $savedFile->filename);
// Create the thumbnails
$this->imagy->createAll($savedFile->path);
return $savedFile;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment