Fixed tour image upload
This commit is contained in:
parent
0d24674dfb
commit
a1c41d08ca
6 changed files with 31 additions and 50 deletions
|
|
@ -12,7 +12,6 @@
|
|||
use Intervention\Image\Facades\Image;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class TourController extends Controller
|
||||
{
|
||||
|
|
@ -114,6 +113,10 @@
|
|||
$tour->is_cancelled = $request->input('is_cancelled', false);
|
||||
$tour->save();
|
||||
|
||||
if ($request->hasFile('bild')) {
|
||||
$this->storeTourImage($request->bild, $tour->id);
|
||||
}
|
||||
|
||||
Log::info("Stored deadline:" . $tour->deadline);
|
||||
|
||||
return redirect('/tour');
|
||||
|
|
@ -295,31 +298,8 @@
|
|||
]
|
||||
);
|
||||
|
||||
if ($request->bild) {
|
||||
$this->storeImage($request->bild, "tour_".$tour->id, $request->name);
|
||||
/*
|
||||
Log::info("Processing image");
|
||||
$bild = Image::make($request->bild);
|
||||
$breite = $bild->width();
|
||||
$hoehe = $bild->height();
|
||||
if ($breite > $hoehe) {
|
||||
Image::make($request->bild)
|
||||
->widen(1200)
|
||||
->save(public_path() . '/img/tour/' . $tour->id . '_gross.jpg');
|
||||
Image::make($request->bild)
|
||||
->widen(64)
|
||||
->save(public_path() . '/img/tour/' . $tour->id . '.jpg');
|
||||
} else {
|
||||
Image::make($request->bild)
|
||||
->heighten(900)
|
||||
->save(public_path() . '/img/tour/' . $tour->id . '_gross.jpg');
|
||||
Image::make($request->bild)
|
||||
->widen(96)
|
||||
->save(public_path() . '/img/tour/' . $tour->id . '.jpg');
|
||||
}
|
||||
Log::info("Image saved as ". public_path() . '/img/tour/' . $tour->id . '_gross.jpg');
|
||||
Log::info("Image saved as ". public_path() . '/img/tour/' . $tour->id . '.jpg');
|
||||
*/
|
||||
if ($request->hasFile('bild')) {
|
||||
$this->storeTourImage($request->bild, $tour->id);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -447,35 +427,34 @@
|
|||
return response()->file(public_path()."/img/placeholder/icon_unknown.png");
|
||||
}
|
||||
|
||||
private function storeImage($bild, $category, $name) {
|
||||
$cat=Str::slug($category);
|
||||
$name=Str::slug($name);
|
||||
|
||||
$dirPath = storage_path() . "/img_storage/$cat";
|
||||
private function storeTourImage($bild, $tourId) {
|
||||
// The tour thumbnail is displayed from public/img/tour, so it has to be
|
||||
// stored there (and not in the gallery directory under storage/).
|
||||
$dirPath = public_path('img/tour');
|
||||
if (!file_exists($dirPath)) {
|
||||
mkdir($dirPath, 0777, true);
|
||||
}
|
||||
|
||||
$bild = Image::make($bild);
|
||||
$breite = $bild->width();
|
||||
$hoehe = $bild->height();
|
||||
$image = Image::make($bild);
|
||||
$breite = $image->width();
|
||||
$hoehe = $image->height();
|
||||
if ($breite > $hoehe) {
|
||||
Image::make($bild)
|
||||
->widen(1200)
|
||||
->save("$dirPath/$name"."_gross.jpg");
|
||||
->save("$dirPath/{$tourId}_gross.jpg");
|
||||
Image::make($bild)
|
||||
->widen(64)
|
||||
->save("$dirPath/$name".".jpg");
|
||||
->save("$dirPath/{$tourId}.jpg");
|
||||
} else {
|
||||
Image::make($bild)
|
||||
->heighten(900)
|
||||
->save("$dirPath/$name"."_gross.jpg");;
|
||||
->save("$dirPath/{$tourId}_gross.jpg");
|
||||
Image::make($bild)
|
||||
->widen(96)
|
||||
->save("$dirPath/$name".".jpg");
|
||||
->save("$dirPath/{$tourId}.jpg");
|
||||
}
|
||||
Log::info("Image saved as $dirPath/$name" . '_gross.jpg');
|
||||
Log::info("Image saved as $dirPath/$name" . '.jpg');
|
||||
Log::info("Image saved as $dirPath/{$tourId}_gross.jpg");
|
||||
Log::info("Image saved as $dirPath/{$tourId}.jpg");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,8 +43,8 @@
|
|||
|
||||
@if(file_exists (public_path ('img/tour/'.$tour->id.'.jpg')))
|
||||
<!--File exists -->
|
||||
<a href="/img/user/{{$tour->id}}_gross.jpg" data-lightbox="{{$tour->id}}_gross.jpg" data-title="{{ $tour->name }}">
|
||||
<img src="/img/user/{{$tour->id}}.jpg" class="mt-3 ml-3" >
|
||||
<a href="/img/tour/{{$tour->id}}_gross.jpg?v={{ filemtime(public_path('img/tour/'.$tour->id.'_gross.jpg')) }}" data-lightbox="{{$tour->id}}_gross.jpg" data-title="{{ $tour->name }}">
|
||||
<img src="/img/tour/{{$tour->id}}.jpg?v={{ filemtime(public_path('img/tour/'.$tour->id.'.jpg')) }}" class="mt-3 ml-3" >
|
||||
</a>
|
||||
@else
|
||||
<img src="/img/placeholder/tour128x100.jpg" class="mt-3 ml-3" >
|
||||
|
|
|
|||
|
|
@ -59,9 +59,10 @@
|
|||
|
||||
@if(file_exists (public_path ('img/tour/'.$tour->id.'.jpg')))
|
||||
<!--File exists -->
|
||||
<a href="/img/tour/{{$tour->id}}_gross.jpg" data-lightbox="{{$tour->id}}_gross.jpg"
|
||||
<a href="/img/tour/{{$tour->id}}_gross.jpg?v={{ filemtime(public_path('img/tour/'.$tour->id.'_gross.jpg')) }}"
|
||||
data-lightbox="{{$tour->id}}_gross.jpg"
|
||||
data-title="{{ $tour->name }}">
|
||||
<img src="/img/tour/{{$tour->id}}.jpg" class="mt-3 ml-3">
|
||||
<img src="/img/tour/{{$tour->id}}.jpg?v={{ filemtime(public_path('img/tour/'.$tour->id.'.jpg')) }}" class="mt-3 ml-3">
|
||||
</a>
|
||||
@else
|
||||
<img src="/img/placeholder/tour128x100.jpg" class="mt-3 ml-3">
|
||||
|
|
|
|||
|
|
@ -36,8 +36,8 @@
|
|||
|
||||
@if(file_exists (public_path ('img/tour/'.$tour->id.'.jpg')))
|
||||
<!--File exists -->
|
||||
<a href="/img/user/{{$tour->id}}_gross.jpg" data-lightbox="{{$tour->id}}_gross.jpg" data-title="{{ $tour->name }}">
|
||||
<img src="/img/user/{{$tour->id}}.jpg" class="mt-3 ml-3" >
|
||||
<a href="/img/tour/{{$tour->id}}_gross.jpg?v={{ filemtime(public_path('img/tour/'.$tour->id.'_gross.jpg')) }}" data-lightbox="{{$tour->id}}_gross.jpg" data-title="{{ $tour->name }}">
|
||||
<img src="/img/tour/{{$tour->id}}.jpg?v={{ filemtime(public_path('img/tour/'.$tour->id.'.jpg')) }}" class="mt-3 ml-3" >
|
||||
</a>
|
||||
@else
|
||||
<img src="/img/placeholder/tour128x100.jpg" class="mt-3 ml-3" >
|
||||
|
|
|
|||
|
|
@ -58,9 +58,10 @@
|
|||
|
||||
@if(file_exists (public_path ('img/tour/'.$tour->id.'.jpg')))
|
||||
<!--File exists -->
|
||||
<a href="/img/tour/{{$tour->id}}_gross.jpg" data-lightbox="{{$tour->id}}_gross.jpg"
|
||||
<a href="/img/tour/{{$tour->id}}_gross.jpg?v={{ filemtime(public_path('img/tour/'.$tour->id.'_gross.jpg')) }}"
|
||||
data-lightbox="{{$tour->id}}_gross.jpg"
|
||||
data-title="{{ $tour->name }}">
|
||||
<img src="/img/tour/{{$tour->id}}.jpg" class="mt-3 ml-3">
|
||||
<img src="/img/tour/{{$tour->id}}.jpg?v={{ filemtime(public_path('img/tour/'.$tour->id.'.jpg')) }}" class="mt-3 ml-3">
|
||||
</a>
|
||||
@else
|
||||
<img src="/img/placeholder/tour128x100.jpg" class="mt-3 ml-3">
|
||||
|
|
|
|||
|
|
@ -44,8 +44,8 @@
|
|||
|
||||
@if(file_exists (public_path ('img/tour/'.$tour->id.'.jpg')))
|
||||
<!--File exists -->
|
||||
<a href="/img/tour/{{$tour->id}}_gross.jpg" data-lightbox="{{$tour->id}}_gross.jpg" data-title="{{ $tour->name }}">
|
||||
<img src="/img/user/{{$tour->id}}.jpg" class="mt-3 ml-3" >
|
||||
<a href="/img/tour/{{$tour->id}}_gross.jpg?v={{ filemtime(public_path('img/tour/'.$tour->id.'_gross.jpg')) }}" data-lightbox="{{$tour->id}}_gross.jpg" data-title="{{ $tour->name }}">
|
||||
<img src="/img/tour/{{$tour->id}}.jpg?v={{ filemtime(public_path('img/tour/'.$tour->id.'.jpg')) }}" class="mt-3 ml-3" >
|
||||
</a>
|
||||
@else
|
||||
<img src="/img/placeholder/tour128x100.jpg" class="mt-3 ml-3" >
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue