setono / sylius-image-plugin
Plugin that will optimize your images in your Sylius store
Installs: 10 773
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 12
Type:sylius-plugin
Requires
- php: >=7.4
- doctrine/orm: ^2.6
- doctrine/persistence: ^2.0 || ^3.0
- knplabs/gaufrette: ^0.8 || ^0.9 || ^0.10 || ^0.11
- liip/imagine-bundle: ^2.6
- psr/event-dispatcher: ^1.0
- setono/doctrine-object-manager-trait: ^1.1
- spatie/data-transfer-object: ^2.8
- sylius/resource-bundle: ^1.8
- symfony/config: ^5.4 || ^6.0
- symfony/console: ^5.4 || ^6.0
- symfony/dependency-injection: ^5.4 || ^6.0
- symfony/event-dispatcher: ^5.4 || ^6.0
- symfony/event-dispatcher-contracts: ^1.1 || ^2.5 || ^3.1
- symfony/filesystem: ^5.4 || ^6.0
- symfony/http-client: ^5.4 || ^6.0
- symfony/http-client-contracts: ^1.1 || ^2.5 || ^3.1
- symfony/http-foundation: ^5.4 || ^6.0
- symfony/lock: ^5.4 || ^6.0
- symfony/messenger: ^5.4 || ^6.0
- symfony/mime: ^5.4 || ^6.0
- symfony/workflow: ^5.4 || ^6.0
- twig/twig: ^2.14 || ^3.4
- webmozart/assert: ^1.11
Requires (Dev)
- api-platform/core: ^2.7
- friendsofsymfony/oauth-server-bundle: >2.0.0-alpha.0 ^2.0@dev
- lexik/jwt-authentication-bundle: ^2.16
- matthiasnoback/symfony-dependency-injection-test: ^4.3
- phpunit/phpunit: ^9.5
- psalm/plugin-phpunit: ^0.18
- psalm/plugin-symfony: ^5.0
- roave/security-advisories: dev-latest
- setono/code-quality-pack: ^2.4
- sylius/admin-api-bundle: ^1.11
- sylius/sylius: ~1.10.14
- symfony/debug-bundle: ^5.4 || ^6.0
- symfony/dotenv: ^5.4 || ^6.0
- symfony/intl: ^5.4 || ^6.0
- symfony/property-info: ^5.4 || ^6.0
- symfony/serializer: ^5.4 || ^6.0
- symfony/web-profiler-bundle: ^5.4 || ^6.0
- symfony/webpack-encore-bundle: ^1.15
- 0.2.x-dev
- 0.1.x-dev
- v0.1.8
- v0.1.7
- v0.1.6
- v0.1.5
- v0.1.4
- v0.1.3
- v0.1.2
- v0.1.1
- v0.1.0
- dev-dependabot/composer/lexik/jwt-authentication-bundle-tw-2.18
- dev-dependabot/composer/phpunit/phpunit-tw-9.6
- dev-dependabot/composer/knplabs/gaufrette-tw-0.8.3
- dev-dependabot/composer/liip/imagine-bundle-tw-2.10
- dev-dependabot/composer/twig/twig-tw-2.15.4
This package is auto-updated.
Last update: 2024-12-03 12:24:00 UTC
README
This library will optimize your images and it works seamlessly with a standard Sylius installation because it has wise fallbacks. Out of the box this plugin uses Cloudflare, so to use it you need a Cloudflare account with the images subscription.
Installation
Step 1: Download the plugin
Open a command console, enter your project directory and execute the following command to download the latest stable version of this plugin:
composer require setono/sylius-image-plugin
Step 2: Enable the plugin
Then, enable the plugin by adding it to the list of registered plugins/bundles
in config/bundles.php
file of your project before (!) SyliusGridBundle
:
<?php $bundles = [ // ... Setono\SyliusImagePlugin\SetonoSyliusImagePlugin::class => ['all' => true], Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true], // ... ];
Step 3: Configure plugin
# config/packages/setono_sylius_image.yaml imports: - { resource: "@SetonoSyliusImagePlugin/Resources/config/app/config.yaml" }
Step 4: Import routing
# config/routes/setono_sylius_image.yaml setono_sylius_image: resource: "@SetonoSyliusImagePlugin/Resources/config/routes.yaml"
Usage
In this plugin we have a concept named variants. These are image variants, i.e. different sizes of images. In a default Sylius installation you use the Liip Imagine Bundle which has a concept of filter sets. In the context of this plugin, these two concepts are more or less similar.
To use the plugin, you have to tell the plugin which variants (filter sets) should be available for optimization and which image resources should be optimized. Here is an example:
Configuration
# config/packages/setono_sylius_image.yaml setono_sylius_image: available_variants: sylius_shop_product_original: ~ sylius_shop_product_tiny_thumbnail: ~ sylius_shop_product_small_thumbnail: ~ sylius_shop_product_thumbnail: ~ sylius_shop_product_large_thumbnail: ~ image_resources: sylius.product_image: variants: - 'sylius_shop_product_original' - 'sylius_shop_product_tiny_thumbnail' - 'sylius_shop_product_small_thumbnail' - 'sylius_shop_product_thumbnail' - 'sylius_shop_product_large_thumbnail'
Effectively this means that for each product image you will have five image variants being optimized. Other variants
like sylius_admin_product_thumbnail
or sylius_large
won't be optimized.
Implement code changes
For the plugin to work the image resources needs to implement an interface. Here is an example of product image resource:
<?php declare(strict_types=1); namespace App\Entity\Product; use Doctrine\ORM\Mapping as ORM; use Setono\SyliusImagePlugin\Model\ImageInterface as SetonoSyliusImagePluginImageInterface; use Setono\SyliusImagePlugin\Model\ImageTrait as SetonoSyliusImagePluginImageTrait; use Sylius\Component\Core\Model\ProductImage as BaseProductImage; /** * @ORM\Entity * @ORM\Table(name="sylius_product_image") */ class ProductImage extends BaseProductImage implements SetonoSyliusImagePluginImageInterface { use SetonoSyliusImagePluginImageTrait; }
Final
Update your database schema
$ php bin/console doctrine:migrations:diff $ php bin/console doctrine:migrations:migrate