This commit is contained in:
Kekskurse 2021-01-20 21:43:58 +01:00
parent 6f2754c7b5
commit 937357b135
6 changed files with 31 additions and 10 deletions

View file

@ -62,6 +62,13 @@ class PublicController extends BaseController
return view("themes.gallery.gallery-detail.list", ["gallery" => $gallery, "tenant" => $tenant, "images" => $images]);
}
public function returnWatermakeFile() {
$tenant = Tenant::query()->where("id", "=", session("current_tenant_id"))->firstOrFail();
$image = Image::query()->where("id", "=", $tenant->watermark)->firstOrFail();
$this->addAccessLog($tenant->id, null, $image->id, "Access", $image->size);
return Storage::disk($image->drive)->response($image->path);
}
public function returnImageFile($tenant_url, $gallery_url, $image_id, Request $request) {
$sizeName = $request->input("size", "medium");
if(!array_key_exists($sizeName, self::$size)) {
@ -110,7 +117,7 @@ class PublicController extends BaseController
}
private function addAccessLog(int $tenant, int $gallery, int $image, string $typ, int $size, $type = "general") {
private function addAccessLog(int $tenant, $gallery, int $image, string $typ, int $size, $type = "general") {
$access = new Access();
$access->year = date("Y");
$access->month = date("m");

View file

@ -77,6 +77,6 @@ class TenantController extends BaseController
$tenant->watermark = $image->id;
$tenant->saveOrFail();
return "OK";
return \redirect("/s/watermark");
}
}

View file

@ -71,10 +71,11 @@ class ResizeImage implements ShouldQueue
$img->resize($newWidth, $newHeight);
//$img->blur(50);
if($this->size > 500 && !is_null($gallery->watermark)) {
if($this->size > 500 && !is_null($tenant->watermark)) {
Log::info("Add Watermark");
$cacheNameWatermark = "";
$waterMarkImage = Image::query()->where("id", "=", $tenant->watermark);
$waterMarkImage = Image::query()->where("id", "=", $tenant->watermark)->firstOrFail();
$watermarkSource = $this->getImage($tenant, $gallery, $waterMarkImage, $cacheNameWatermark);
$watermark = $manager->make($watermarkSource);
@ -103,6 +104,8 @@ class ResizeImage implements ShouldQueue
//$font->angle(45);
});
*/
} else {
Log::info("No Watermark");
}
@ -115,7 +118,7 @@ class ResizeImage implements ShouldQueue
//Storage::disk("cache")->put($cacheName."_".$this->size, $image->getImageAsString(IMAGETYPE_JPEG, 100));
}
private function getImage($tenant, $gallery, $image, $cacheName) {
private function getImage(Tenant $tenant, Gallery $gallery, Image $image, $cacheName) {
if (Storage::disk('cache')->exists($cacheName."_orginal")) {
$file = Storage::disk("cache")->get($cacheName."_orginal");
} else {

View file

@ -21,6 +21,10 @@ class ImageWatermark extends Migration
Schema::table("tenants", function (Blueprint $table) {
$table->unsignedBigInteger("watermark")->nullable()->default(null);
});
Schema::table("access", function (Blueprint $table) {
$table->unsignedBigInteger("gallery")->nullable()->change();
});
}
/**

View file

@ -2,6 +2,16 @@
@section('content')
<h1>Watermark</h1>
<div class="row">
<div class="col-md-6">
<form method="post" enctype="multipart/form-data">
@csrf
<input type="file" name="files[]" class="form-control" >
<input type="submit" value="Upload Watermark" class="btn btn-outline-success">
</form>
</div>
<div class="col-md-6">Current Watermark:<br><img src="/s/watermark/image" style="max-width: 100%;"></div>
</div>
@if ($errors->any())
<div class="alert alert-danger">
<ul>
@ -11,11 +21,7 @@
</ul>
</div>
@endif
<form method="post" enctype="multipart/form-data">
@csrf
<input type="file" name="files[]" class="form-control" >
<input type="submit" value="Upload Watermark" class="btn btn-outline-success">
</form>
@endsection

View file

@ -47,6 +47,7 @@ Route::middleware([\App\Http\Middleware\TenanMiddleware::class])->group(function
Route::post("/g/{url}/save", [\App\Http\Controllers\GalleryController::class, 'saveImage']);
Route::get("/s/watermark", [\App\Http\Controllers\TenantController::class, 'watermarkView']);
Route::post("/s/watermark", [\App\Http\Controllers\TenantController::class, 'watermarkSave']);
Route::get("/s/watermark/image", [\App\Http\Controllers\PublicController::class, "returnWatermakeFile"]);
});
Route::get("/{name}", [\App\Http\Controllers\PublicController::class, 'listGalleriesView'])->middleware([\App\Http\Middleware\TenanMiddleware::class]);