From 042e78583ea8a4bd7b8f28215f1dfeb747db1ee6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Wed, 6 Sep 2023 17:56:52 +0200 Subject: [PATCH] add image resizer --- composer.json | 1 + composer.lock | 278 +++++++++++++++++- config/image-resizer.php | 69 +++++ .../views/pages/products/indexList.blade.php | 194 ++++++------ 4 files changed, 441 insertions(+), 101 deletions(-) create mode 100644 config/image-resizer.php diff --git a/composer.json b/composer.json index 4137d78..60c1fc0 100644 --- a/composer.json +++ b/composer.json @@ -12,6 +12,7 @@ "carlos-meneses/laravel-mpdf": "^2.1", "diglactic/laravel-breadcrumbs": "^8.0", "guzzlehttp/guzzle": "^7.2", + "kwaadpepper/image-resizer": "^2.1", "laravel/framework": "^10.0", "laravel/tinker": "^2.8" }, diff --git a/composer.lock b/composer.lock index ce07a81..12b398c 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": "72bd46bbe723badbb255fbe8130d9305", + "content-hash": "681daf9716dc063b99412ff470a716dc", "packages": [ { "name": "brick/math", @@ -1154,6 +1154,217 @@ ], "time": "2021-10-07T12:57:01+00:00" }, + { + "name": "intervention/image", + "version": "2.7.2", + "source": { + "type": "git", + "url": "https://github.com/Intervention/image.git", + "reference": "04be355f8d6734c826045d02a1079ad658322dad" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Intervention/image/zipball/04be355f8d6734c826045d02a1079ad658322dad", + "reference": "04be355f8d6734c826045d02a1079ad658322dad", + "shasum": "" + }, + "require": { + "ext-fileinfo": "*", + "guzzlehttp/psr7": "~1.1 || ^2.0", + "php": ">=5.4.0" + }, + "require-dev": { + "mockery/mockery": "~0.9.2", + "phpunit/phpunit": "^4.8 || ^5.7 || ^7.5.15" + }, + "suggest": { + "ext-gd": "to use GD library based image processing.", + "ext-imagick": "to use Imagick based image processing.", + "intervention/imagecache": "Caching extension for the Intervention Image library" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.4-dev" + }, + "laravel": { + "providers": [ + "Intervention\\Image\\ImageServiceProvider" + ], + "aliases": { + "Image": "Intervention\\Image\\Facades\\Image" + } + } + }, + "autoload": { + "psr-4": { + "Intervention\\Image\\": "src/Intervention/Image" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Oliver Vogel", + "email": "oliver@intervention.io", + "homepage": "https://intervention.io/" + } + ], + "description": "Image handling and manipulation library with support for Laravel integration", + "homepage": "http://image.intervention.io/", + "keywords": [ + "gd", + "image", + "imagick", + "laravel", + "thumbnail", + "watermark" + ], + "support": { + "issues": "https://github.com/Intervention/image/issues", + "source": "https://github.com/Intervention/image/tree/2.7.2" + }, + "funding": [ + { + "url": "https://paypal.me/interventionio", + "type": "custom" + }, + { + "url": "https://github.com/Intervention", + "type": "github" + } + ], + "time": "2022-05-21T17:30:32+00:00" + }, + { + "name": "intervention/imagecache", + "version": "2.6.0", + "source": { + "type": "git", + "url": "https://github.com/Intervention/imagecache.git", + "reference": "86136575a62d3634b51f196a998fce4a583b49bb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Intervention/imagecache/zipball/86136575a62d3634b51f196a998fce4a583b49bb", + "reference": "86136575a62d3634b51f196a998fce4a583b49bb", + "shasum": "" + }, + "require": { + "illuminate/cache": "^5.5|~6|~7|~8|~9|~10", + "illuminate/filesystem": "^5.5|~6|~7|~8|~9|~10", + "intervention/image": "~2.2", + "nesbot/carbon": "^2.39", + "opis/closure": "^3.5", + "php": "~7.2|~8" + }, + "require-dev": { + "phpunit/phpunit": "^8.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Intervention\\Image\\": "src/Intervention/Image" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Oliver Vogel", + "email": "oliver@intervention.io", + "homepage": "http://intervention.io/" + } + ], + "description": "Caching extension for the Intervention Image Class", + "homepage": "https://image.intervention.io", + "keywords": [ + "cache", + "gd", + "image", + "imagick", + "laravel" + ], + "support": { + "issues": "https://github.com/Intervention/imagecache/issues", + "source": "https://github.com/Intervention/imagecache/tree/2.6.0" + }, + "funding": [ + { + "url": "https://paypal.me/interventionio", + "type": "custom" + }, + { + "url": "https://github.com/Intervention", + "type": "github" + } + ], + "time": "2023-02-25T19:40:47+00:00" + }, + { + "name": "kwaadpepper/image-resizer", + "version": "2.1.0", + "source": { + "type": "git", + "url": "https://github.com/Kwaadpepper/image-resizer.git", + "reference": "2a14ad153b34916f437af50549bad47c018902df" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Kwaadpepper/image-resizer/zipball/2a14ad153b34916f437af50549bad47c018902df", + "reference": "2a14ad153b34916f437af50549bad47c018902df", + "shasum": "" + }, + "require": { + "illuminate/support": "~10", + "intervention/image": "^2.7.2", + "intervention/imagecache": "^2.6", + "laravel/framework": "~10" + }, + "require-dev": { + "slevomat/coding-standard": "^8.11" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Kwaadpepper\\ImageResizer\\ImageResizerServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Kwaadpepper\\ImageResizer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jérémy Munsch", + "email": "github@jeremydev.ovh", + "homepage": "https://jeremydev.ovh" + } + ], + "description": "Resize images on the fly and cache them", + "homepage": "https://github.com/kwaadpepper/image-resizer", + "keywords": [ + "images", + "laravel", + "resize" + ], + "support": { + "issues": "https://github.com/Kwaadpepper/image-resizer/issues", + "source": "https://github.com/Kwaadpepper/image-resizer/tree/2.1.0" + }, + "time": "2023-06-08T12:07:24+00:00" + }, { "name": "laravel/framework", "version": "v10.10.1", @@ -2548,6 +2759,71 @@ ], "time": "2023-02-08T01:06:31+00:00" }, + { + "name": "opis/closure", + "version": "3.6.3", + "source": { + "type": "git", + "url": "https://github.com/opis/closure.git", + "reference": "3d81e4309d2a927abbe66df935f4bb60082805ad" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/opis/closure/zipball/3d81e4309d2a927abbe66df935f4bb60082805ad", + "reference": "3d81e4309d2a927abbe66df935f4bb60082805ad", + "shasum": "" + }, + "require": { + "php": "^5.4 || ^7.0 || ^8.0" + }, + "require-dev": { + "jeremeamia/superclosure": "^2.0", + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.6.x-dev" + } + }, + "autoload": { + "files": [ + "functions.php" + ], + "psr-4": { + "Opis\\Closure\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marius Sarca", + "email": "marius.sarca@gmail.com" + }, + { + "name": "Sorin Sarca", + "email": "sarca_sorin@hotmail.com" + } + ], + "description": "A library that can be used to serialize closures (anonymous functions) and arbitrary objects.", + "homepage": "https://opis.io/closure", + "keywords": [ + "anonymous functions", + "closure", + "function", + "serializable", + "serialization", + "serialize" + ], + "support": { + "issues": "https://github.com/opis/closure/issues", + "source": "https://github.com/opis/closure/tree/3.6.3" + }, + "time": "2022-01-27T09:35:39+00:00" + }, { "name": "paragonie/random_compat", "version": "v9.99.100", diff --git a/config/image-resizer.php b/config/image-resizer.php new file mode 100644 index 0000000..0da808e --- /dev/null +++ b/config/image-resizer.php @@ -0,0 +1,69 @@ + 'imagick', + + /** + * The cache driver to use as defined + * in config/cache of your app + */ + 'cache' => 'file', + + /** + * The path where to store image in cache + */ + 'cachePath' => 'cache/images', + + /** + * Image cache life time + * This is given in minutes + * Here the cache for images is + * one hour + */ + 'lifetime' => 60, + + /** + * Format can specifiy to which format save the image + * JPEG PNG GIF TIF BMP ICO PSD WebP + * GD ✔️ ✔️ ✔️ - - - - ✔️ * + * Imagick ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ * + * For WebP support GD driver must be used with PHP 5 >= 5.5.0 or PHP 7 + * in order to use imagewebp(). If Imagick is used, it must be compiled + * with libwebp for WebP support. + * resize => will resize the image (boolean) + * fit => Combine cropping and resizing to format image in a smart way (boolean) + * keepRatio => will keep image ratio wile resizing (boolean) + * trim => boolean to trim the image using border color + * inCanvas => to make sure image boundarie is respected + * format => select tha wantd ouput form, yan can just convert images if you want + * example : + * 'small' => [ + * 'height' => 500, + * 'width' => 250, + * 'inCanvas' => true, + * 'trim' => ['transparent', null, 10] + * ], + * 'smallWebp' => [ + * 'height' => 500, + * 'width' => 250, + * 'inCanvas' => true, + * 'format' => 'webp' + * ], + * 'justconvertImage' => [ + * 'format' => 'webp' + * ] + */ + 'templates' => [ + 'productTiny' => [ + 'height' => 180, + 'width' => 180, + 'resize' => true, + 'keepRatio' => true, + 'format' => 'jpg', + ], + ] +]; diff --git a/resources/views/pages/products/indexList.blade.php b/resources/views/pages/products/indexList.blade.php index f363e0e..5378825 100644 --- a/resources/views/pages/products/indexList.blade.php +++ b/resources/views/pages/products/indexList.blade.php @@ -1,109 +1,103 @@
- +
- @php - $cols = [ - 'name' => __('Nom'), - 'brand_id' => __('Marque'), - 'picture' => __('Image'), - 'multi_pdf' => __('Générer en pdf la sélection'), - ]; - $routeName = request()->route()->getName(); - $rst = !is_null(request()->rst) || !Session::has("$routeName.sorted"); - $noOrder = Session::get("$routeName.sort_col") !== 'order' and (Session::has("$routeName.sort_col") or Session::has("$routeName.sort_way")); - $noOrder = Session::get("$routeName.sort_col") !== '' and (Session::has("$routeName.sort_col") or Session::has("$routeName.sort_way")); - @endphp - @include('modules.table-col-sorter', ['cols' => $cols, 'mobileHide' => [], 'ignore' => ['multi_pdf']]) + @php + $cols = [ + 'name' => __('Nom'), + 'brand_id' => __('Marque'), + 'picture' => __('Image'), + 'multi_pdf' => __('Générer en pdf la sélection'), + ]; + $routeName = request() + ->route() + ->getName(); + $rst = !is_null(request()->rst) || !Session::has("$routeName.sorted"); + ($noOrder = Session::get("$routeName.sort_col") !== 'order') and (Session::has("$routeName.sort_col") or Session::has("$routeName.sort_way")); + ($noOrder = Session::get("$routeName.sort_col") !== '') and (Session::has("$routeName.sort_col") or Session::has("$routeName.sort_way")); + @endphp + @include('modules.table-col-sorter', ['cols' => $cols, 'mobileHide' => [], 'ignore' => ['multi_pdf']]) @if ($products->count()) - @foreach ($products as $productModel) - - - - - {{-- @if(!$noOrder or $rst) --}} - - {{-- @endif --}} - - - @endforeach + @foreach ($products as $productModel) + + + + + {{-- @if (!$noOrder or $rst) --}} + + {{-- @endif --}} + + + @endforeach @else - - - + + + @endif
- {{ $productModel->name }} - - @foreach($brands as $key => $brand) - @if ($brand->id === $productModel->brand_id) -

{{ $brand->name }}

- @endif - @endforeach -
- @if(isset($productModel->picture)) - - @else -

{{ __('Aucune image enregistée') }}

- @endif -
- @php - $data = [ - 'id' => 'productSelectMultiPdf', - 'model' => $productModel, - 'printMultiProduct' => $printMultiProduct, - ]; - @endphp -
-
-
- @method('DELETE') - @csrf - -
-
+ {{ $productModel->name }} + + @foreach ($brands as $key => $brand) + @if ($brand->id === $productModel->brand_id) +

{{ $brand->name }}

+ @endif + @endforeach +
+ @if ($productModel->picture) + + @else +

{{ __('Aucune image enregistée') }}

+ @endif +
+ @php + $data = [ + 'id' => 'productSelectMultiPdf', + 'model' => $productModel, + 'printMultiProduct' => $printMultiProduct, + ]; + @endphp +
+
+
+ @method('DELETE') + @csrf + +
+
- {{ __('Aucun résultat pour les :models', ['models' => trans_choice('models.classes.products_monitoring', 2)]) }} - -
+ {{ __('Aucun résultat pour les :models', ['models' => trans_choice('models.classes.products_monitoring', 2)]) }} + +