From 6f2754c7b5e674e02175f9ae0f26bc6f6fd81966 Mon Sep 17 00:00:00 2001 From: Kekskurse Date: Wed, 20 Jan 2021 21:25:29 +0100 Subject: [PATCH] Stuff --- .idea/kuvia.iml | 3 + .idea/php.xml | 3 + app/Console/Commands/EXIFRead.php | 1 + app/Http/Controllers/GalleryController.php | 1 + app/Http/Controllers/PublicController.php | 2 +- app/Http/Controllers/TenantController.php | 27 ++ app/Jobs/ResizeImage.php | 37 +- composer.json | 1 + composer.lock | 380 +++++++++++++++++- .../2021_01_20_192143_image_watermark.php | 35 ++ resources/views/tenant/watermark.blade.php | 21 + routes/web.php | 2 + 12 files changed, 498 insertions(+), 15 deletions(-) create mode 100644 database/migrations/2021_01_20_192143_image_watermark.php create mode 100644 resources/views/tenant/watermark.blade.php diff --git a/.idea/kuvia.iml b/.idea/kuvia.iml index 81ecb19..74689e6 100644 --- a/.idea/kuvia.iml +++ b/.idea/kuvia.iml @@ -13,6 +13,9 @@ + + + diff --git a/.idea/php.xml b/.idea/php.xml index ebd36e7..771c9f1 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -115,6 +115,9 @@ + + + diff --git a/app/Console/Commands/EXIFRead.php b/app/Console/Commands/EXIFRead.php index 02d4cb0..174bc8b 100644 --- a/app/Console/Commands/EXIFRead.php +++ b/app/Console/Commands/EXIFRead.php @@ -41,6 +41,7 @@ class EXIFRead extends Command { $images = Image::query() ->where("exifRead", "=", 0) + ->where("typ", "=", "gallery") ->limit(10) ->get(); foreach ($images as $image) { diff --git a/app/Http/Controllers/GalleryController.php b/app/Http/Controllers/GalleryController.php index a868716..d23c2ba 100644 --- a/app/Http/Controllers/GalleryController.php +++ b/app/Http/Controllers/GalleryController.php @@ -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)) { diff --git a/app/Http/Controllers/PublicController.php b/app/Http/Controllers/PublicController.php index 8a96fa1..eb92e0a 100644 --- a/app/Http/Controllers/PublicController.php +++ b/app/Http/Controllers/PublicController.php @@ -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"); diff --git a/app/Http/Controllers/TenantController.php b/app/Http/Controllers/TenantController.php index d21760c..2880f33 100644 --- a/app/Http/Controllers/TenantController.php +++ b/app/Http/Controllers/TenantController.php @@ -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"; + } } diff --git a/app/Jobs/ResizeImage.php b/app/Jobs/ResizeImage.php index b2156e9..3368a48 100644 --- a/app/Jobs/ResizeImage.php +++ b/app/Jobs/ResizeImage.php @@ -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) { diff --git a/composer.json b/composer.json index 32a815c..1cd7903 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/composer.lock b/composer.lock index 233a5f8..7a08742 100644 --- a/composer.lock +++ b/composer.lock @@ -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", diff --git a/database/migrations/2021_01_20_192143_image_watermark.php b/database/migrations/2021_01_20_192143_image_watermark.php new file mode 100644 index 0000000..82d4e00 --- /dev/null +++ b/database/migrations/2021_01_20_192143_image_watermark.php @@ -0,0 +1,35 @@ +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() + { + // + } +} diff --git a/resources/views/tenant/watermark.blade.php b/resources/views/tenant/watermark.blade.php new file mode 100644 index 0000000..3c303d9 --- /dev/null +++ b/resources/views/tenant/watermark.blade.php @@ -0,0 +1,21 @@ +@extends('layout/template') + +@section('content') +

Watermark

+ @if ($errors->any()) +
+
    + @foreach ($errors->all() as $error) +
  • {{ $error }}
  • + @endforeach +
+
+ @endif +
+ @csrf + + +
+ +@endsection + diff --git a/routes/web.php b/routes/web.php index e82d7ae..c795751 100644 --- a/routes/web.php +++ b/routes/web.php @@ -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]);