parent
a9f40e55e7
commit
18dd6cd92d
@ -10,6 +10,8 @@ use DateTime;
|
|||||||
use Illuminate\Http\UploadedFile;
|
use Illuminate\Http\UploadedFile;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Support\Facades\Redirect;
|
use Illuminate\Support\Facades\Redirect;
|
||||||
|
use Intervention\Image\Constraint;
|
||||||
|
use Intervention\Image\Facades\Image;
|
||||||
|
|
||||||
class HomeController extends Controller
|
class HomeController extends Controller
|
||||||
{
|
{
|
||||||
@ -145,6 +147,10 @@ class HomeController extends Controller
|
|||||||
$uploaded_document = $validated_data['file'];
|
$uploaded_document = $validated_data['file'];
|
||||||
$file_name = $uploaded_document->getClientOriginalName();
|
$file_name = $uploaded_document->getClientOriginalName();
|
||||||
$uploaded_document->storeAs(Auth::user()->getFolder(), $file_name);
|
$uploaded_document->storeAs(Auth::user()->getFolder(), $file_name);
|
||||||
|
$img = Image::make($uploaded_document->getRealPath());
|
||||||
|
$img->resize(300, null, static function (Constraint $constraint) {
|
||||||
|
$constraint->aspectRatio();
|
||||||
|
})->save(sprintf('%s/%s/%s', storage_path('app'), Auth::user()->getFolder(), sprintf('300-%s', $file_name)));
|
||||||
$data['image'] = $file_name;
|
$data['image'] = $file_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,21 +31,22 @@ class ImageController extends Controller
|
|||||||
throw new UnauthorizedHttpException('Cette image ne vous appartient pas.');
|
throw new UnauthorizedHttpException('Cette image ne vous appartient pas.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$path = sprintf('%s/%s/%s', storage_path('app'), Auth::user()->getFolder(), $image);
|
$original = sprintf('%s/%s/%s', storage_path('app'), Auth::user()->getFolder(), $image);
|
||||||
if (!is_readable($path)) {
|
$thumb = sprintf('%s/%s/300-%s', storage_path('app'), Auth::user()->getFolder(), $image);
|
||||||
|
$img = Image::make($original);
|
||||||
|
if ('o:full' === $options) {
|
||||||
|
if (!is_readable($original)) {
|
||||||
|
throw new NotFoundHttpException();
|
||||||
|
}
|
||||||
|
} elseif (!is_readable($thumb)) {
|
||||||
|
if (!is_readable($original)) {
|
||||||
throw new NotFoundHttpException();
|
throw new NotFoundHttpException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$img = Image::make($path);
|
|
||||||
|
|
||||||
if ('o:full' !== $options) {
|
|
||||||
$options = explode('!', $options);
|
$options = explode('!', $options);
|
||||||
$width = null;
|
$width = null;
|
||||||
$height = null;
|
$height = null;
|
||||||
foreach ($options as $option) {
|
foreach ($options as $option) {
|
||||||
$current_option = explode(':', $option);
|
[$current_option_name, $current_option_value] = explode(':', $option);
|
||||||
foreach ($current_option as $current_option_name => $current_option_value) {
|
|
||||||
switch ($current_option_name) {
|
switch ($current_option_name) {
|
||||||
case 'w':
|
case 'w':
|
||||||
$width = $current_option_value;
|
$width = $current_option_value;
|
||||||
@ -55,14 +56,15 @@ class ImageController extends Controller
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
//http://image.intervention.io/getting_started/
|
//http://image.intervention.io/getting_started/
|
||||||
$img->resize($width, $height, static function (Constraint $constraint) {
|
$img->resize($width, $height, static function (Constraint $constraint) {
|
||||||
$constraint->aspectRatio();
|
$constraint->aspectRatio();
|
||||||
});
|
})->save(sprintf('%s/%s/%s', storage_path('app'), Auth::user()->getFolder(), sprintf('300-%s', $image)));
|
||||||
|
} else {
|
||||||
|
$img = Image::make($thumb);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $img->response(File::extension($path));
|
return $img->response(File::extension($original));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user