This commit is contained in:
Kekskurse 2021-01-20 21:25:29 +01:00
parent 6f4ebf6a96
commit 6f2754c7b5
12 changed files with 498 additions and 15 deletions

View File

@ -13,6 +13,9 @@
<excludeFolder url="file://$MODULE_DIR$/vendor/brick/math" />
<excludeFolder url="file://$MODULE_DIR$/vendor/composer" />
<excludeFolder url="file://$MODULE_DIR$/vendor/dnoegel/php-xdg-base-dir" />
<excludeFolder url="file://$MODULE_DIR$/vendor/doctrine/cache" />
<excludeFolder url="file://$MODULE_DIR$/vendor/doctrine/dbal" />
<excludeFolder url="file://$MODULE_DIR$/vendor/doctrine/event-manager" />
<excludeFolder url="file://$MODULE_DIR$/vendor/doctrine/inflector" />
<excludeFolder url="file://$MODULE_DIR$/vendor/doctrine/instantiator" />
<excludeFolder url="file://$MODULE_DIR$/vendor/doctrine/lexer" />

View File

@ -115,6 +115,9 @@
<path value="$PROJECT_DIR$/vendor/gumlet/php-image-resize" />
<path value="$PROJECT_DIR$/vendor/erusev/parsedown" />
<path value="$PROJECT_DIR$/vendor/intervention/image" />
<path value="$PROJECT_DIR$/vendor/doctrine/cache" />
<path value="$PROJECT_DIR$/vendor/doctrine/event-manager" />
<path value="$PROJECT_DIR$/vendor/doctrine/dbal" />
</include_path>
</component>
<component name="PhpUnit">

View File

@ -41,6 +41,7 @@ class EXIFRead extends Command
{
$images = Image::query()
->where("exifRead", "=", 0)
->where("typ", "=", "gallery")
->limit(10)
->get();
foreach ($images as $image) {

View File

@ -194,6 +194,7 @@ class GalleryController extends BaseController
$image->filename = $validated["files"][0]->getClientOriginalName();
$image->gallery = $gallery->id;
$image->size = $validated["files"][0]->getSize();
$image->typ = "gallery";
$image->saveOrFail();
if(is_null($gallery->main_image)) {

View File

@ -110,7 +110,7 @@ class PublicController extends BaseController
}
private function addAccessLog(int $tenant, int $gallery, int $image, string $typ, int $size) {
private function addAccessLog(int $tenant, int $gallery, int $image, string $typ, int $size, $type = "general") {
$access = new Access();
$access->year = date("Y");
$access->month = date("m");

View File

@ -2,6 +2,7 @@
namespace App\Http\Controllers;
use App\Models\Image;
use App\Models\Tenant;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
@ -52,4 +53,30 @@ class TenantController extends BaseController
private function switchTenantById($id) {
session(["current_tenant_id" => $id]);
}
public function watermarkView() {
return view("tenant.watermark");
}
public function watermarkSave(Request $request) {
$validated = $request->validate([
'files.0' => 'required|image'
]);
$path = $validated["files"][0]->store("watermark/".session("current_tenant_id"));
$image = new Image();
$image->path = $path;
$image->driver = env('FILESYSTEM_DRIVER', 'local');
$image->filename = $validated["files"][0]->getClientOriginalName();
$image->gallery = null;
$image->size = $validated["files"][0]->getSize();
$image->typ = "watermark";
$image->saveOrFail();
$tenant = Tenant::query()->where("id", "=", session("current_tenant_id"))->firstOrFail();
$tenant->watermark = $image->id;
$tenant->saveOrFail();
return "OK";
}
}

View File

@ -51,17 +51,7 @@ class ResizeImage implements ShouldQueue
$cacheName = "cache/".$tenant->url."_".$gallery->url."_".$image->id;
//Check if orginal size is cached on the current system
if (Storage::disk('cache')->exists($cacheName."_orginal")) {
$file = Storage::disk("cache")->get($cacheName."_orginal");
} else {
$this->addAccessLog($tenant->id, $gallery->id, $image->id, "Access", $image->size);
$file = Storage::disk($image->driver)->get($image->path);
if(env("CACHE_ORGINAL"))
{
Storage::disk("cache")->put($cacheName."_orginal", $file);
}
}
$file = $this->getImage($tenant, $gallery, $image, $cacheName);
$manager = new ImageManager(array('driver' => 'imagick'));
$img = $manager->make($file);
@ -81,8 +71,13 @@ class ResizeImage implements ShouldQueue
$img->resize($newWidth, $newHeight);
//$img->blur(50);
if($this->size > 500) {
$watermark = $manager->make(storage_path("logo-sample.png"));
if($this->size > 500 && !is_null($gallery->watermark)) {
$cacheNameWatermark = "";
$waterMarkImage = Image::query()->where("id", "=", $tenant->watermark);
$watermarkSource = $this->getImage($tenant, $gallery, $waterMarkImage, $cacheNameWatermark);
$watermark = $manager->make($watermarkSource);
if($watermark->getWidth() > $img->getWidth()) {
$newWidth = $img->getWidth() / 1.2;
$newHeight = $watermark->getHeight() * ($newWidth / $watermark->getWidth());
@ -96,6 +91,8 @@ class ResizeImage implements ShouldQueue
$watermark->opacity(40);
$img->insert($watermark, 'center');
/*
* Reddit like balken unten
$img->resizeCanvas(0, 28, 'top', true, "#000000");
$img->text('www.kuvia.cloud/'.$tenant->url, $img->getWidth() - 10, $img->getHeight() - 25, function($font) {
$font->file(storage_path("OpenSans-Light.ttf"));
@ -105,6 +102,7 @@ class ResizeImage implements ShouldQueue
$font->valign('top');
//$font->angle(45);
});
*/
}
@ -117,6 +115,19 @@ class ResizeImage implements ShouldQueue
//Storage::disk("cache")->put($cacheName."_".$this->size, $image->getImageAsString(IMAGETYPE_JPEG, 100));
}
private function getImage($tenant, $gallery, $image, $cacheName) {
if (Storage::disk('cache')->exists($cacheName."_orginal")) {
$file = Storage::disk("cache")->get($cacheName."_orginal");
} else {
$this->addAccessLog($tenant->id, $gallery->id, $image->id, "Access", $image->size);
$file = Storage::disk($image->driver)->get($image->path);
if (env("CACHE_ORGINAL")) {
Storage::disk("cache")->put($cacheName . "_orginal", $file);
}
}
return $file;
}
private function addAccessLog(int $tenant, int $gallery, int $image, string $typ, int $size) {

View File

@ -10,6 +10,7 @@
"require": {
"php": "^7.3|^8.0",
"almasaeed2010/adminlte": "^3.0",
"doctrine/dbal": "^3.0",
"erusev/parsedown": "^1.7",
"fideloper/proxy": "^4.4",
"fruitcake/laravel-cors": "^2.0",

380
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "fd0ab766a01c2bf348b0108782d792d7",
"content-hash": "aad8aae4d553fd85e9d879debb23bada",
"packages": [
{
"name": "almasaeed2010/adminlte",
@ -251,6 +251,79 @@
],
"time": "2020-08-18T23:57:15+00:00"
},
{
"name": "composer/package-versions-deprecated",
"version": "1.11.99.1",
"source": {
"type": "git",
"url": "https://github.com/composer/package-versions-deprecated.git",
"reference": "7413f0b55a051e89485c5cb9f765fe24bb02a7b6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/composer/package-versions-deprecated/zipball/7413f0b55a051e89485c5cb9f765fe24bb02a7b6",
"reference": "7413f0b55a051e89485c5cb9f765fe24bb02a7b6",
"shasum": ""
},
"require": {
"composer-plugin-api": "^1.1.0 || ^2.0",
"php": "^7 || ^8"
},
"replace": {
"ocramius/package-versions": "1.11.99"
},
"require-dev": {
"composer/composer": "^1.9.3 || ^2.0@dev",
"ext-zip": "^1.13",
"phpunit/phpunit": "^6.5 || ^7"
},
"type": "composer-plugin",
"extra": {
"class": "PackageVersions\\Installer",
"branch-alias": {
"dev-master": "1.x-dev"
}
},
"autoload": {
"psr-4": {
"PackageVersions\\": "src/PackageVersions"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Marco Pivetta",
"email": "ocramius@gmail.com"
},
{
"name": "Jordi Boggiano",
"email": "j.boggiano@seld.be"
}
],
"description": "Composer plugin that provides efficient querying for installed package versions (no runtime IO)",
"support": {
"issues": "https://github.com/composer/package-versions-deprecated/issues",
"source": "https://github.com/composer/package-versions-deprecated/tree/1.11.99.1"
},
"funding": [
{
"url": "https://packagist.com",
"type": "custom"
},
{
"url": "https://github.com/composer",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/composer/composer",
"type": "tidelift"
}
],
"time": "2020-11-11T10:22:58+00:00"
},
{
"name": "dnoegel/php-xdg-base-dir",
"version": "v0.1.1",
@ -288,6 +361,311 @@
},
"time": "2019-12-04T15:06:13+00:00"
},
{
"name": "doctrine/cache",
"version": "1.10.2",
"source": {
"type": "git",
"url": "https://github.com/doctrine/cache.git",
"reference": "13e3381b25847283a91948d04640543941309727"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/cache/zipball/13e3381b25847283a91948d04640543941309727",
"reference": "13e3381b25847283a91948d04640543941309727",
"shasum": ""
},
"require": {
"php": "~7.1 || ^8.0"
},
"conflict": {
"doctrine/common": ">2.2,<2.4"
},
"require-dev": {
"alcaeus/mongo-php-adapter": "^1.1",
"doctrine/coding-standard": "^6.0",
"mongodb/mongodb": "^1.1",
"phpunit/phpunit": "^7.0",
"predis/predis": "~1.0"
},
"suggest": {
"alcaeus/mongo-php-adapter": "Required to use legacy MongoDB driver"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.9.x-dev"
}
},
"autoload": {
"psr-4": {
"Doctrine\\Common\\Cache\\": "lib/Doctrine/Common/Cache"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Guilherme Blanco",
"email": "guilhermeblanco@gmail.com"
},
{
"name": "Roman Borschel",
"email": "roman@code-factory.org"
},
{
"name": "Benjamin Eberlei",
"email": "kontakt@beberlei.de"
},
{
"name": "Jonathan Wage",
"email": "jonwage@gmail.com"
},
{
"name": "Johannes Schmitt",
"email": "schmittjoh@gmail.com"
}
],
"description": "PHP Doctrine Cache library is a popular cache implementation that supports many different drivers such as redis, memcache, apc, mongodb and others.",
"homepage": "https://www.doctrine-project.org/projects/cache.html",
"keywords": [
"abstraction",
"apcu",
"cache",
"caching",
"couchdb",
"memcached",
"php",
"redis",
"xcache"
],
"support": {
"issues": "https://github.com/doctrine/cache/issues",
"source": "https://github.com/doctrine/cache/tree/1.10.x"
},
"funding": [
{
"url": "https://www.doctrine-project.org/sponsorship.html",
"type": "custom"
},
{
"url": "https://www.patreon.com/phpdoctrine",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Fcache",
"type": "tidelift"
}
],
"time": "2020-07-07T18:54:01+00:00"
},
{
"name": "doctrine/dbal",
"version": "3.0.0",
"source": {
"type": "git",
"url": "https://github.com/doctrine/dbal.git",
"reference": "ee6d1260d5cc20ec506455a585945d7bdb98662c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/dbal/zipball/ee6d1260d5cc20ec506455a585945d7bdb98662c",
"reference": "ee6d1260d5cc20ec506455a585945d7bdb98662c",
"shasum": ""
},
"require": {
"composer/package-versions-deprecated": "^1.11.99",
"doctrine/cache": "^1.0",
"doctrine/event-manager": "^1.0",
"php": "^7.3 || ^8.0"
},
"require-dev": {
"doctrine/coding-standard": "^8.1",
"jetbrains/phpstorm-stubs": "^2019.1",
"phpstan/phpstan": "^0.12.40",
"phpstan/phpstan-strict-rules": "^0.12.2",
"phpunit/phpunit": "^9.4",
"psalm/plugin-phpunit": "^0.10.0",
"symfony/console": "^2.0.5|^3.0|^4.0|^5.0",
"vimeo/psalm": "^3.17.2"
},
"suggest": {
"symfony/console": "For helpful console commands such as SQL execution and import of files."
},
"bin": [
"bin/doctrine-dbal"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Doctrine\\DBAL\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Guilherme Blanco",
"email": "guilhermeblanco@gmail.com"
},
{
"name": "Roman Borschel",
"email": "roman@code-factory.org"
},
{
"name": "Benjamin Eberlei",
"email": "kontakt@beberlei.de"
},
{
"name": "Jonathan Wage",
"email": "jonwage@gmail.com"
}
],
"description": "Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.",
"homepage": "https://www.doctrine-project.org/projects/dbal.html",
"keywords": [
"abstraction",
"database",
"db2",
"dbal",
"mariadb",
"mssql",
"mysql",
"oci8",
"oracle",
"pdo",
"pgsql",
"postgresql",
"queryobject",
"sasql",
"sql",
"sqlite",
"sqlserver",
"sqlsrv"
],
"support": {
"issues": "https://github.com/doctrine/dbal/issues",
"source": "https://github.com/doctrine/dbal/tree/3.0.0"
},
"funding": [
{
"url": "https://www.doctrine-project.org/sponsorship.html",
"type": "custom"
},
{
"url": "https://www.patreon.com/phpdoctrine",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Fdbal",
"type": "tidelift"
}
],
"time": "2020-11-15T18:20:41+00:00"
},
{
"name": "doctrine/event-manager",
"version": "1.1.1",
"source": {
"type": "git",
"url": "https://github.com/doctrine/event-manager.git",
"reference": "41370af6a30faa9dc0368c4a6814d596e81aba7f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/event-manager/zipball/41370af6a30faa9dc0368c4a6814d596e81aba7f",
"reference": "41370af6a30faa9dc0368c4a6814d596e81aba7f",
"shasum": ""
},
"require": {
"php": "^7.1 || ^8.0"
},
"conflict": {
"doctrine/common": "<2.9@dev"
},
"require-dev": {
"doctrine/coding-standard": "^6.0",
"phpunit/phpunit": "^7.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Doctrine\\Common\\": "lib/Doctrine/Common"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Guilherme Blanco",
"email": "guilhermeblanco@gmail.com"
},
{
"name": "Roman Borschel",
"email": "roman@code-factory.org"
},
{
"name": "Benjamin Eberlei",
"email": "kontakt@beberlei.de"
},
{
"name": "Jonathan Wage",
"email": "jonwage@gmail.com"
},
{
"name": "Johannes Schmitt",
"email": "schmittjoh@gmail.com"
},
{
"name": "Marco Pivetta",
"email": "ocramius@gmail.com"
}
],
"description": "The Doctrine Event Manager is a simple PHP event system that was built to be used with the various Doctrine projects.",
"homepage": "https://www.doctrine-project.org/projects/event-manager.html",
"keywords": [
"event",
"event dispatcher",
"event manager",
"event system",
"events"
],
"support": {
"issues": "https://github.com/doctrine/event-manager/issues",
"source": "https://github.com/doctrine/event-manager/tree/1.1.x"
},
"funding": [
{
"url": "https://www.doctrine-project.org/sponsorship.html",
"type": "custom"
},
{
"url": "https://www.patreon.com/phpdoctrine",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Fevent-manager",
"type": "tidelift"
}
],
"time": "2020-05-29T18:28:51+00:00"
},
{
"name": "doctrine/inflector",
"version": "2.0.3",

View File

@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class ImageWatermark extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table("images", function (Blueprint $table) {
$table->unsignedBigInteger("gallery")->nullable()->change();
$table->enum("typ", ["gallery", "watermark"])->default("gallery");
});
Schema::table("tenants", function (Blueprint $table) {
$table->unsignedBigInteger("watermark")->nullable()->default(null);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}

View File

@ -0,0 +1,21 @@
@extends('layout/template')
@section('content')
<h1>Watermark</h1>
@if ($errors->any())
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</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

@ -45,6 +45,8 @@ Route::middleware([\App\Http\Middleware\TenanMiddleware::class])->group(function
Route::get("/g/{url}/setDefault", [\App\Http\Controllers\GalleryController::class, 'setDefault']);
Route::get("/g/{url}/delete", [\App\Http\Controllers\GalleryController::class, 'deleteImage']);
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("/{name}", [\App\Http\Controllers\PublicController::class, 'listGalleriesView'])->middleware([\App\Http\Middleware\TenanMiddleware::class]);