### Setup Python Virtual Environment Source: https://github.com/liip/liipimaginebundle/wiki/Building-RST-Documentation Installs the 'virtualenv' package using pip and then creates and activates a new isolated Python virtual environment named '.venv' in the parent directory. This prevents dependency conflicts. ```bash # install virtualenv package python -m pip install --user virtualenv # use virtualenv to create a virtual environment python -m virtualenv ../.venv # enter the newly created virtual environment source ../.venv/bin/activate ``` -------------------------------- ### Install LiipImagineBundle with Composer Source: https://github.com/liip/liipimaginebundle/blob/2.x/Resources/doc/installation.rst This command downloads the LiipImagineBundle and adds it as a project dependency. It's the first step in integrating image manipulation capabilities into your Symfony application. ```bash composer require liip/imagine-bundle ``` -------------------------------- ### Install System Dependencies for Linux/macOS Source: https://github.com/liip/liipimaginebundle/wiki/Building-RST-Documentation Installs essential system dependencies like python, pip, make, and git using package managers for various Linux distributions and macOS. Note: Instructions may need adjustment for Windows. ```bash # debian-based (ubuntu, mint, etc) using apt apt install python python-pip make git # centos and red hat enterprise linux using yum yum install epel-release yum install python python-pip make git # fedora using dnf dnf install python2 python2-pip make git # archlinux using pacman pacman -S python2 python2-pip make git # opensuse using zypper and pip installation script zypper install python make git wget https://bootstrap.pypa.io/get-pip.py sudo python get-pip.py rm get-pip.py # mac osx using homebrew /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" brew install python make git ``` -------------------------------- ### Install Python Build Requirements Source: https://github.com/liip/liipimaginebundle/wiki/Building-RST-Documentation Installs all necessary Python packages for building the documentation using pip, referencing the requirements file located at '_build/.requirements.txt' within the Symfony documentation repository. ```bash # install python build requirements pip install -r _build/.requirements.txt ``` -------------------------------- ### Install OneupFlysystemBundle (Bash) Source: https://github.com/liip/liipimaginebundle/blob/2.x/Resources/doc/cache-resolver/flysystem.rst This command installs the OneupFlysystemBundle using Composer, a prerequisite for using the FlysystemResolver with LiipImagineBundle. ```bash composer require oneup/flysystem-bundle ``` -------------------------------- ### Implement Custom Image Post-Processor for Optimization Source: https://context7.com/liip/liipimaginebundle/llms.txt Shows how to create a custom post-processor for binary optimization by implementing the PostProcessorInterface. This example uses an external command-line tool to optimize images. ```php getMimeType(), ['image/png', 'image/jpeg'])) { return $binary; } // Create temporary file $tempFile = tempnam(sys_get_temp_dir(), 'imagine_'); file_put_contents($tempFile, $binary->getContent()); // Run optimizer $process = new Process([$this->binaryPath, $tempFile]); $process->run(); if ($process->isSuccessful()) { $result = new Binary( file_get_contents($tempFile), $binary->getMimeType(), $binary->getFormat() ); } else { $result = $binary; } unlink($tempFile); return $result; } } ``` -------------------------------- ### Navigate to LiipImagineBundle Repository Source: https://github.com/liip/liipimaginebundle/wiki/Building-RST-Documentation Clones the LiipImagineBundle repository if it doesn't exist locally, then navigates into the repository's root directory. Alternatively, it allows entering an existing local copy. ```bash # IF you do not have a copy, clone a new one and enter it git clone https://github.com/liip/LiipImagineBundle.git imagine-bundle cd imagine-bundle # OR if you already have a local working copy simply enter it cd /home/user/project/my-local-imagine-copy ``` -------------------------------- ### Compile Documentation with Make Source: https://github.com/liip/liipimaginebundle/wiki/Building-RST-Documentation Compiles the RST documentation files into HTML format using the 'make' command. This command should be executed from the root directory of the Symfony documentation repository. ```bash # Ensure you are in the Symfony documentation repository root make ``` -------------------------------- ### LiipImagineBundle Dependency Injection Compiler Pass Logging Example Source: https://github.com/liip/liipimaginebundle/blob/2.x/UPGRADE.md Example output from LiipImagineBundle's dependency injection compiler passes, showing registered services like loaders, filters, post-processors, and cache resolvers. This logging helps in debugging tagged services in Symfony applications. ```log LoadersCompilerPass: Registered imagine-bimdle binary loader: liip_imagine.binary.loader.default FiltersCompilerPass: Registered imagine-bimdle filter loader: liip_imagine.filter.loader.relative_resize FiltersCompilerPass: Registered imagine-bimdle filter loader: liip_imagine.filter.loader.resize FiltersCompilerPass: Registered imagine-bimdle filter loader: liip_imagine.filter.loader.thumbnail FiltersCompilerPass: Registered imagine-bimdle filter loader: liip_imagine.filter.loader.crop FiltersCompilerPass: Registered imagine-bimdle filter loader: liip_imagine.filter.loader.grayscale FiltersCompilerPass: Registered imagine-bimdle filter loader: liip_imagine.filter.loader.paste FiltersCompilerPass: Registered imagine-bimdle filter loader: liip_imagine.filter.loader.watermark FiltersCompilerPass: Registered imagine-bimdle filter loader: liip_imagine.filter.loader.background FiltersCompilerPass: Registered imagine-bimdle filter loader: liip_imagine.filter.loader.strip FiltersCompilerPass: Registered imagine-bimdle filter loader: liip_imagine.filter.loader.scale FiltersCompilerPass: Registered imagine-bimdle filter loader: liip_imagine.filter.loader.upscale FiltersCompilerPass: Registered imagine-bimdle filter loader: liip_imagine.filter.loader.downscale FiltersCompilerPass: Registered imagine-bimdle filter loader: liip_imagine.filter.loader.auto_rotate FiltersCompilerPass: Registered imagine-bimdle filter loader: liip_imagine.filter.loader.rotate FiltersCompilerPass: Registered imagine-bimdle filter loader: liip_imagine.filter.loader.interlace PostProcessorsCompilerPass: Registered imagine-bimdle filter post-processor: liip_imagine.filter.post_processor.jpegoptim PostProcessorsCompilerPass: Registered imagine-bimdle filter post-processor: liip_imagine.filter.post_processor.optipng PostProcessorsCompilerPass: Registered imagine-bimdle filter post-processor: liip_imagine.filter.post_processor.pngquant PostProcessorsCompilerPass: Registered imagine-bimdle filter post-processor: liip_imagine.filter.post_processor.mozjpeg ResolversCompilerPass: Registered imagine-bimdle cache resolver: liip_imagine.cache.resolver.default ResolversCompilerPass: Registered imagine-bimdle cache resolver: liip_imagine.cache.resolver.no_cache_web_path ``` -------------------------------- ### Clone Symfony Docs and Link Imagine Bundle Source: https://github.com/liip/liipimaginebundle/wiki/Building-RST-Documentation Clones the Symfony documentation repository, enters it, creates a symbolic link to the LiipImagineBundle's documentation directory, and updates the Symfony documentation's index file to include the bundle. ```bash # clone the symfony documentation repo and enter it git clone https://github.com/symfony/symfony-docs symfony-docs cd symfony-docs # create symbolic link to imagine bundle repo ln -s ../Resources/doc/ liip-imagine-bundle # add imagine reference to symfony's index file echo -ne "\n.. toctree::\n :hidden:\n\n liip-imagine-bundle/index\n" >> index.rst ``` -------------------------------- ### Register LiipImagineBundle Routes Source: https://github.com/liip/liipimaginebundle/blob/2.x/Resources/doc/installation.rst Register the bundle's routes to make its image manipulation functionalities accessible. This can be done using either YAML or XML configuration files. ```yaml # app/config/route/liip_imagine.yml _liip_imagine: resource: "@LiipImagineBundle/Resources/config/routing.yaml" ``` ```xml ``` -------------------------------- ### Enable LiipImagineBundle in config/bundles.php (Symfony >= 5) Source: https://github.com/liip/liipimaginebundle/blob/2.x/Resources/doc/installation.rst For Symfony 5.x and later, enable the bundle by adding its class to the return statement in your config/bundles.php file. This is the modern way to register bundles in Symfony. ```php ['all' => true] ]; ``` -------------------------------- ### Run Enqueue Consumers (Bash) Source: https://github.com/liip/liipimaginebundle/blob/2.x/Resources/doc/optimizations/resolve-cache-images-in-background.rst This command starts the Enqueue consumers in the background, which are necessary to process the image resolution messages sent by LiipImagineBundle. It requires the Symfony CLI and the Enqueue library to be installed. ```bash ./bin/console enqueue:consume --setup-broker -vvv ``` -------------------------------- ### Complete Production Filter Set Example Source: https://context7.com/liip/liipimaginebundle/llms.txt A comprehensive LiipImagineBundle configuration for production, including driver selection (Imagick), resolvers, loaders, default quality settings, and detailed filter sets for user avatars, product galleries, and responsive images. It also incorporates post-processors for image optimization. ```yaml liip_imagine: driver: imagick resolvers: default: web_path: web_root: "%kernel.project_dir%/public" cache_prefix: "media/cache" loaders: default: filesystem: data_root: - "%kernel.project_dir%/public" - "%kernel.project_dir%/var/uploads" default_filter_set_settings: quality: 85 jpeg_quality: 82 png_compression_level: 7 filter_sets: # User avatar with auto-rotation and optimization avatar: quality: 80 filters: auto_rotate: ~ thumbnail: size: [150, 150] mode: outbound allow_upscale: true background: size: [150, 150] color: '#f5f5f5' post_processors: jpegoptim: strip_all: true max: 75 progressive: true # Product gallery with watermark product_gallery: quality: 90 filters: auto_rotate: ~ thumbnail: size: [800, 600] mode: inset background: size: [800, 600] position: center color: '#ffffff' watermark_image: image: assets/images/watermark.png size: 0.15 position: bottomright post_processors: jpegoptim: strip_all: true max: 85 progressive: true # Responsive image sizes responsive_sm: filters: thumbnail: { size: [320, 240], mode: outbound } strip: ~ responsive_md: filters: thumbnail: { size: [768, 576], mode: outbound } strip: ~ responsive_lg: filters: thumbnail: { size: [1200, 900], mode: outbound } strip: ~ ``` -------------------------------- ### Install aws-sdk-php Dependency Source: https://github.com/liip/liipimaginebundle/blob/2.x/Resources/doc/cache-resolver/amazons3.rst This command installs the 'aws-sdk-php' library, which is a dependency for the AmazonS3Resolver. It should be executed in your project's root directory. ```bash composer require aws/aws-sdk-php ``` -------------------------------- ### Enable LiipImagineBundle in Symfony AppKernel (Symfony < 5) Source: https://github.com/liip/liipimaginebundle/blob/2.x/Resources/doc/installation.rst For older Symfony versions, enable the bundle by adding its class to the registerBundles method in your AppKernel.php file. This makes the bundle's services available to your application. ```php filterService->getUrlOfFilteredImage( $path, 'my_thumb' ); // Get URL with runtime filters $customUrl = $this->filterService->getUrlOfFilteredImageWithRuntimeFilters( $path, 'my_thumb', ['thumbnail' => ['size' => [100, 100]]] ); // Explicitly warm up cache $this->filterService->warmUpCache($path, 'my_thumb'); // Force cache regeneration $this->filterService->warmUpCache($path, 'my_thumb', null, true); // Bust (remove) cache for an image $this->filterService->bustCache($path, 'my_thumb'); return [ 'thumbnail' => $thumbnailUrl, 'custom' => $customUrl, ]; } } ``` -------------------------------- ### Thumbnail Filter Configuration Examples Source: https://context7.com/liip/liipimaginebundle/llms.txt Provides YAML configurations for the thumbnail filter within Liip Imagine Bundle. It showcases different modes like 'outbound' and 'inset', and how to set fixed dimensions with the 'fixed' filter. ```yaml # config/packages/liip_imagine.yaml liip_imagine: filter_sets: # Basic thumbnail with cropping small_thumb: filters: thumbnail: size: [120, 90] mode: outbound allow_upscale: false # Thumbnail that fits within bounds without cropping medium_inset: filters: thumbnail: size: [300, 300] mode: inset # Fixed size thumbnail (always outputs exact dimensions with upscaling) fixed_avatar: filters: fixed: width: 150 height: 150 ``` -------------------------------- ### Configure Flysystem Resolver with OneupFlysystemBundle (YAML) Source: https://github.com/liip/liipimaginebundle/blob/2.x/Resources/doc/cache-resolver/flysystem.rst Example YAML configuration for LiipImagineBundle to use the FlysystemResolver with OneupFlysystemBundle. It specifies the filesystem service, root URL, cache prefix, and visibility settings. ```yaml liip_imagine: resolvers: profile_photos: flysystem: filesystem_service: oneup_flysystem.profile_photos_filesystem root_url: "https://images.example.com" cache_prefix: media/cache visibility: public oneup_flysystem: adapters: profile_photos: local: directory: "path/to/profile/photos" filesystems: profile_photos: adapter: profile_photos ``` -------------------------------- ### Install Symfony Messenger for LiipImagineBundle Source: https://github.com/liip/liipimaginebundle/blob/2.x/Resources/doc/optimizations/resolve-cache-images-in-background.rst Installs the Symfony Messenger component using Composer, which is required for asynchronous image cache warmup. This step sets up the necessary foundation for message queue integration. ```bash composer require symfony/messenger ``` -------------------------------- ### Set Custom OptiPNG Binary Path (YAML) Source: https://github.com/liip/liipimaginebundle/blob/2.x/Resources/doc/post-processors/png-opti.rst This configuration shows how to specify a custom path for the optipng executable. This is necessary if optipng is not installed in the default location (/usr/bin/optipng). Ensure the provided path is correct for your system. ```yaml # app/config/config.yml parameters: liip_imagine.optipng.binary: /your/custom/path/to/optipng ``` -------------------------------- ### Cache Management via Console Commands (Bash) Source: https://context7.com/liip/liipimaginebundle/llms.txt Provides examples of using Symfony console commands to manage the LiipImagineBundle cache. Commands include resolving (warming up) cache for specific images and filters, and removing cache entries. These are useful for deployment scripts and maintenance. ```bash # Resolve (warm up) cache for specific images and filters php bin/console liip:imagine:cache:resolve images/photo1.jpg images/photo2.jpg --filter=my_thumb # Resolve cache for all filters php bin/console liip:imagine:cache:resolve images/photo1.jpg # Resolve cache for multiple filters php bin/console liip:imagine:cache:resolve images/photo1.jpg --filter=my_thumb --filter=large_thumb # Remove cache for specific paths and filters php bin/console liip:imagine:cache:remove images/photo1.jpg --filter=my_thumb # Remove all cache for specific paths php bin/console liip:imagine:cache:remove images/photo1.jpg images/photo2.jpg # Remove all cache for a filter php bin/console liip:imagine:cache:remove --filter=my_thumb # Remove ALL cached images php bin/console liip:imagine:cache:remove ``` -------------------------------- ### Configure Flysystem Loader with The League FlysystemBundle Source: https://github.com/liip/liipimaginebundle/blob/2.x/Resources/doc/data-loader/flysystem.rst Example YAML configuration for LiipImagineBundle and The League FlysystemBundle. It sets up the Flysystem loader, referencing a specific filesystem storage service. Note the comment advising against using the full Flysystem service alias. ```yaml # /config/liip_imagine.yaml liip_imagine: loaders: profile_photos: flysystem: #⚠️ do not use the full flysystem service alias (which would be `flysystem.adapter.profile_photos.storage`) filesystem_service: 'profile_photos.storage' data_loader: profile_photos # /config/flysystem.yaml flysystem: storages: profile_photos.storage: adapter: 'local' options: directory: "path/to/profile/photos" ``` -------------------------------- ### Configure Pngquant Post-Processor in YAML Source: https://github.com/liip/liipimaginebundle/blob/2.x/Resources/doc/post-processors/png-quant.rst This YAML configuration demonstrates how to integrate the PngquantPostProcessor into a filter set for image optimization. It specifies the quality range for the compression. Ensure pngquant is installed on your system. ```yaml # app/config/config.yml liip_imagine: filter_sets: my_thumb: filters: thumbnail: { size: [120, 90], mode: outbound } background: { size: [124, 94], position: center, color: '#000' } post_processors: pngquant: { quality: "75-85" } ``` -------------------------------- ### Configure Flysystem Loader with OneupFlysystemBundle Source: https://github.com/liip/liipimaginebundle/blob/2.x/Resources/doc/data-loader/flysystem.rst Example YAML configuration for LiipImagineBundle and OneupFlysystemBundle. It specifies the Flysystem loader and the associated filesystem service. The `filesystem_service` points to the service defined in the `oneup_flysystem.yaml` configuration. ```yaml # /config/liip_imagine.yaml liip_imagine: loaders: profile_photos: flysystem: filesystem_service: oneup_flysystem.profile_photos_filesystem data_loader: profile_photos # /config/oneup_flysystem.yaml oneup_flysystem: adapters: profile_photos: local: location: "path/to/profile/photos" filesystems: profile_photos: adapter: profile_photos ``` -------------------------------- ### Use LiipImagineBundle FilterService in Controller (PHP) Source: https://github.com/liip/liipimaginebundle/blob/2.x/README.md Shows how to inject and utilize the `liip_imagine.service.filter` service within a Symfony controller to get image URLs, with options for simple filtering or runtime configuration. ```php container ->get('liip_imagine.service.filter'); // 1) Simple filter $resourcePath = $imagine->getUrlOfFilteredImage('uploads/foo.jpg', 'my_thumb'); // 2) Runtime configuration $runtimeConfig = [ 'thumbnail' => [ 'size' => [200, 200] ], ]; $resourcePath = $imagine->getUrlOfFilteredImageWithRuntimeFilters( 'uploads/foo.jpg', 'my_thumb', $runtimeConfig ); // .. } } ?> ``` -------------------------------- ### Apply Runtime Options in Twig Template Source: https://github.com/liip/liipimaginebundle/blob/2.x/README.md This Twig example shows how to override filter set options at runtime. It defines a `runtimeConfig` to change the thumbnail size to 50x50px for a specific image. ```twig {% set runtimeConfig = {"thumbnail": {"size": [50, 50] }} %} ``` -------------------------------- ### Resolving Image Paths Programmatically in PHP Source: https://github.com/liip/liipimaginebundle/blob/2.x/Resources/doc/basic-usage.rst Shows how to programmatically resolve filtered image URLs using the `getBrowserPath` method of the `Liip\ImagineBundle\Imagine\Cache\CacheManager` service. Includes an example within a Symfony controller. ```php $imagineCacheManager->getBrowserPath('/relative/path/to/image.jpg', 'my_thumb'); ``` ```php getBrowserPath('/relative/path/to/image.jpg', 'my_thumb'); // ... } } ``` -------------------------------- ### Runtime Filter Configuration in Twig and PHP Source: https://github.com/liip/liipimaginebundle/blob/2.x/Resources/doc/basic-usage.rst Demonstrates how to dynamically alter filter behavior at runtime by passing an options array. This is useful for handling edge cases without defining new filters. It shows examples for both Twig and PHP template environments. ```html+twig {% set runtimeConfig = {"thumbnail": {"size": [50, 50] }} %} ``` ```html+php [ "size" => [50, 50] ] ]; ?> ``` -------------------------------- ### Run Messenger Consumers Source: https://github.com/liip/liipimaginebundle/blob/2.x/Resources/doc/optimizations/resolve-cache-images-in-background.rst Starts a Symfony Messenger consumer for the 'liip_imagine' transport. This command processes messages from the queue to warm up the image cache asynchronously, with specified time and memory limits. ```bash php bin/console messenger:consume liip_imagine --time-limit=3600 --memory-limit=256M ``` -------------------------------- ### Set Custom Pngquant Binary Path in YAML Source: https://github.com/liip/liipimaginebundle/blob/2.x/Resources/doc/post-processors/png-quant.rst This YAML configuration shows how to specify a custom path for the pngquant executable if it's not located at the default '/usr/bin/pngquant'. This is necessary if pngquant is installed in a non-standard location. ```yaml # app/config/config.yml parameters: liip_imagine.pngquant.binary: /your/custom/path/to/pngquant ``` -------------------------------- ### Use Custom LiipImagineBundle Filter in Configuration (YAML) Source: https://github.com/liip/liipimaginebundle/blob/2.x/Resources/doc/filters.rst Shows how to reference and utilize a custom filter, registered either automatically or manually, within the LiipImagineBundle configuration. The example defines a filter set named 'my_special_style' that includes the custom filter 'my_custom_filter'. ```yaml # app/config/config.yml liip_imagine: filter_sets: my_special_style: filters: my_custom_filter: { } ``` -------------------------------- ### Twig Integration for Liip Imagine Bundle Source: https://context7.com/liip/liipimaginebundle/llms.txt Demonstrates how to use the `imagine_filter` and `imagine_filter_cache` Twig filters to apply image transformations and retrieve cached image URLs. It includes examples for basic usage, runtime configuration overrides, and creating responsive images with fallbacks. ```twig {# Basic usage - apply a filter set to an image #} {# With runtime configuration to override filter options #} {% set runtimeConfig = {"thumbnail": {"size": [50, 50]}} %} {# Get the cached image URL directly (assumes cache is already warmed) #} {# WebP with fallback using picture element #} Photo ``` -------------------------------- ### Install Symfony Cache Component Source: https://github.com/liip/liipimaginebundle/blob/2.x/Resources/doc/cache-resolver/psr_cache.rst Installs the Symfony Cache component, a PSR-6 implementation required by the PsrCacheResolver. This command should be executed in your project directory. ```bash composer require symfony/cache ``` -------------------------------- ### Install Doctrine Cache Dependency Source: https://github.com/liip/liipimaginebundle/blob/2.x/Resources/doc/cache-resolver/cache.rst This command installs the Doctrine Cache library, which is a dependency for the deprecated Cache Resolver in LiipImagineBundle. It is executed using Composer. ```bash $ composer require doctrine/cache ``` -------------------------------- ### Configure Liip Imagine with Flysystem Integration Source: https://context7.com/liip/liipimaginebundle/llms.txt This configuration integrates LiipImagineBundle with Flysystem. It sets up a 'flysystem_loader' to use the 'oneup_flysystem.source_filesystem' and a 'flysystem_resolver' for caching, pointing to 'oneup_flysystem.cache_filesystem' with a specified root URL and cache prefix. The data loader and cache are then set to these Flysystem-based services. ```yaml liip_imagine: loaders: flysystem_loader: flysystem: filesystem_service: oneup_flysystem.source_filesystem resolvers: flysystem_resolver: flysystem: filesystem_service: oneup_flysystem.cache_filesystem root_url: "https://cdn.example.com/cache" cache_prefix: images data_loader: flysystem_loader cache: flysystem_resolver ``` -------------------------------- ### Set Object GET Options via Constructor (YAML) Source: https://github.com/liip/liipimaginebundle/blob/2.x/Resources/doc/cache-resolver/aws_s3.rst This YAML configuration for `services.yml` shows how to inject multiple GET options directly into the AwsS3Resolver constructor. This is an alternative to using `setGetOption` calls. ```yaml # app/config/services.yml services: acme.imagine.cache.resolver.aws_s3_resolver: class: Liip\ImagineBundle\Imagine\Cache\Resolver\AwsS3Resolver arguments: - "@acme.amazon_s3" - "%amazon_s3.bucket%" - "public-read" # Aws\S3\Enum\CannedAcl::PUBLIC_READ (default) - { Scheme: https } tags: - { name: "liip_imagine.cache.resolver", resolver: "aws_s3_resolver" } ``` -------------------------------- ### Flysystem Integration for Data Loading and Caching Source: https://context7.com/liip/liipimaginebundle/llms.txt Illustrates the integration of Flysystem adapters for both data loading and cache resolving, enabling the use of various storage solutions compatible with Flysystem. ```yaml # config/packages/liip_imagine.yaml liip_imagine: # Example using Flysystem for data loading loaders: flysystem_loader: flysystem: adapter: 'league.flysystem.local.local_adapter' # Replace with your Flysystem adapter service ID prefix: 'images' # Example using Flysystem for cache resolving resolvers: flysystem_resolver: flysystem: adapter: 'league.flysystem.aws_s3_v3.aws_s3_v3_adapter' # Replace with your Flysystem adapter service ID prefix: 'cached_images' filter_sets: flysystem_example: data_loader: flysystem_loader cache: flysystem_resolver filters: thumbnail: size: [100, 100] mode: outbound ``` -------------------------------- ### Basic Liip Imagine Bundle Configuration Source: https://context7.com/liip/liipimaginebundle/llms.txt Sets up the basic configuration for the Liip Imagine Bundle, including the image processing driver, cache resolvers, data loaders, and default filter set settings. It also defines a sample filter set named 'my_thumb'. ```yaml # config/packages/liip_imagine.yaml liip_imagine: # Image processing driver: gd, imagick, gmagick, or vips driver: gd # Configure cache resolvers resolvers: default: web_path: web_root: "%kernel.project_dir%/public" cache_prefix: "media/cache" # Configure data loaders loaders: default: filesystem: data_root: "%kernel.project_dir%/public" # Default settings for all filter sets default_filter_set_settings: quality: 100 jpeg_quality: ~ png_compression_level: ~ animated: false # Define your filter sets filter_sets: cache: ~ my_thumb: quality: 75 filters: thumbnail: { size: [120, 90], mode: outbound } background: { size: [124, 94], position: center, color: '#000000' } ``` -------------------------------- ### Include Apache Configuration File in VHost for LiipImagineBundle Source: https://github.com/liip/liipimaginebundle/blob/2.x/README.md This method demonstrates including a separate Apache configuration file within the VHost configuration. This approach allows for better organization and easier management of environment-specific configurations. The included file should contain the necessary Alias and Directory directives. ```xml Include "/path/to/your/project/app/config/apache/photos.xml" ``` -------------------------------- ### Set Object GET Options via Service Calls (YAML) Source: https://github.com/liip/liipimaginebundle/blob/2.x/Resources/doc/cache-resolver/aws_s3.rst This YAML configuration for `services.yml` demonstrates how to set specific GET options for the AwsS3Resolver using service calls. The `setGetOption` method is used to configure options like 'Scheme'. ```yaml # app/config/services.yml services: acme.imagine.cache.resolver.aws_s3_resolver: class: Liip\ImagineBundle\Imagine\Cache\Resolver\AwsS3Resolver arguments: - "@acme.amazon_s3" - "%amazon_s3.bucket%" calls: # This calls $service->setGetOption('Scheme', 'https'); - [ setGetOption, [ Scheme, https ] ] tags: - { name: "liip_imagine.cache.resolver", resolver: "aws_s3_resolver" } ``` -------------------------------- ### Configure Apache VHost with Alias for LiipImagineBundle Source: https://github.com/liip/liipimaginebundle/blob/2.x/README.md This configuration snippet shows how to set up an Apache VHost to serve images from a specific directory using an alias. It requires granting read access to the directory and defining an Alias directive. The relative path to an image will be mapped to the alias path. ```xml Alias /FavouriteAlias /path/to/source/images/dir AllowOverride None Allow from All ``` -------------------------------- ### Configure Image Scaling and Resizing Filters Source: https://context7.com/liip/liipimaginebundle/llms.txt Demonstrates various scaling and resizing options available in LiipImagineBundle. Filters include 'scale' for ratio or dimension-based scaling, 'relative_resize' for proportional adjustments, 'upscale' for minimum dimensions, and 'downscale' for maximum dimensions. ```yaml liip_imagine: filter_sets: # Scale by ratio (0.5 = 50% of original size) half_size: filters: scale: to: 0.5 # Scale to fit within dimensions proportionally fit_dimensions: filters: scale: dim: [800, 600] # Relative resize - set specific dimension, scale proportionally widen_to_500: filters: relative_resize: widen: 500 heighten_to_300: filters: relative_resize: heighten: 300 # Downscale only if image is larger than max dimensions max_size: filters: downscale: max: [1920, 1080] # Upscale only if image is smaller than min dimensions min_size: filters: upscale: min: [800, 600] ``` -------------------------------- ### Configure Enqueue Filesystem Transport Source: https://github.com/liip/liipimaginebundle/blob/2.x/Resources/doc/optimizations/resolve-cache-images-in-background.rst Provides a minimal configuration for the Enqueue Bundle using the filesystem transport in `app/config/config.yml`. This setup is for the deprecated Enqueue integration with LiipImagineBundle. ```yaml enqueue: default: ``` -------------------------------- ### Configure Flysystem Adapters and Filesystems Source: https://context7.com/liip/liipimaginebundle/llms.txt This configuration sets up two Flysystem adapters: 'source_adapter' for local storage and 'cache_adapter' for AWS S3 V3. It then defines two filesystems, 'source' and 'cache', mapping them to their respective adapters. The AWS S3 adapter requires a client and bucket configuration. ```yaml oneup_flysystem: adapters: source_adapter: local: location: "%kernel.project_dir%/var/uploads" cache_adapter: awss3v3: client: Aws\S3\S3Client bucket: "%env(AWS_S3_BUCKET)%" prefix: "cache" filesystems: source: adapter: source_adapter cache: adapter: cache_adapter ``` -------------------------------- ### Configure LiipImagineBundle Data Roots (YAML) Source: https://github.com/liip/liipimaginebundle/blob/2.x/README.md Illustrates how to configure the `data_root` parameter in `config.yml` to specify directories from which LiipImagineBundle should load images. Supports single paths, multiple paths, and automatic registration of bundle resources. ```yaml liip_imagine: loaders: default: filesystem: data_root: /path/to/source/images/dir ``` ```yaml liip_imagine: loaders: default: filesystem: data_root: - /path/foo - /path/bar ``` ```yaml liip_imagine: loaders: default: filesystem: bundle_resources: enabled: true ``` ```yaml liip_imagine: loaders: default: filesystem: bundle_resources: enabled: true access_control_type: blacklist access_control_list: - FooBundle - BarBundle ``` ```yaml liip_imagine: loaders: default: filesystem: bundle_resources: enabled: true access_control_type: whitelist access_control_list: - FooBundle - BarBundle ``` -------------------------------- ### Configure OneupFlysystem Adapters and Filesystems for S3 Source: https://github.com/liip/liipimaginebundle/blob/2.x/Resources/doc/events.rst This YAML configuration sets up adapters and filesystems for OneupFlysystem to interact with AWS S3. It defines separate adapters for original images and cached images with specific prefixes, and then mounts them to filesystem services. ```yaml #oneup_flysystem.yaml oneup_flysystem: adapters: # Original image addapter user_adapter: awss3v3: client: Aws\S3\S3Client bucket: '%env(IONOS_S3_BUCKET_NAME)%' prefix: "users" # Original image location # One adapter per filter and the location of the generated images, with the cache_prefix user_thumbnail_adapter: awss3v3: client: Aws\S3\S3Client bucket: '%env(IONOS_S3_BUCKET_NAME)%' prefix: "cache/user_thumbnail" user_medium_adapter: awss3v3: client: Aws\S3\S3Client bucket: '%env(IONOS_S3_BUCKET_NAME)%' prefix: "cache/user_medium" filesystems: user: adapter: user_adapter mount: user userThumbnail: adapter: user_thumbnail_adapter mount: userThumbnail userMedium: adapter: user_medium_adapter mount: userMedium ``` -------------------------------- ### Configure FileSystem Data Loader with Multiple Roots Source: https://context7.com/liip/liipimaginebundle/llms.txt Sets up the FileSystem data loader to load images from multiple directories within the project or from bundle resources. This allows for flexible image sourcing. ```yaml # config/packages/liip_imagine.yaml liip_imagine: loaders: default: filesystem: data_root: - "%kernel.project_dir%/public" - "%kernel.project_dir%/var/uploads" # Named data roots for explicit file references uploads_loader: filesystem: data_root: public: "%kernel.project_dir%/public/images" uploads: "%kernel.project_dir%/var/uploads" user_content: "%kernel.project_dir%/var/user-content" # Load from bundle resources bundle_loader: filesystem: bundle_resources: enabled: true access_control_type: whitelist access_control_list: - AppBundle - AcmeBundle filter_sets: user_avatar: data_loader: uploads_loader filters: thumbnail: size: [150, 150] mode: outbound ``` -------------------------------- ### Configure Stream Loader with Gaufrette Wrapper (YAML) Source: https://github.com/liip/liipimaginebundle/blob/2.x/Resources/doc/data-loader/stream.rst This configuration snippet shows how to set up the StreamLoader to use a Gaufrette filesystem wrapper for loading images. It specifies the 'stream' type loader and the 'wrapper' pointing to the Gaufrette filesystem. ```yaml liip_imagine: loaders: stream.profile_photos: stream: wrapper: gaufrette://profile_photos ``` -------------------------------- ### Set Custom cwebp Binary Path in YAML Source: https://github.com/liip/liipimaginebundle/blob/2.x/Resources/doc/post-processors/cwebp.rst This YAML configuration shows how to specify a custom path for the cwebp executable if it's not located at the default '/usr/bin/cwebp'. This is necessary when the binary is installed in a non-standard location. ```yaml # app/config/config.yml parameters: liip_imagine.cwebp.binary: /your/custom/path/to/cwebp ``` -------------------------------- ### Configure WebP Generation and Filter Sets Source: https://context7.com/liip/liipimaginebundle/llms.txt This configuration enables WebP generation for all filter sets with a default quality and also shows how to set a specific WebP quality for a filter set. It also demonstrates defining dual formats (JPEG and WebP) for client-side detection. ```yaml liip_imagine: # Enable WebP generation for all filter sets webp: generate: true quality: 80 # Or set WebP as default output format default_filter_set_settings: format: webp filter_sets: # Specific WebP quality per filter high_quality_webp: format: webp quality: 95 filters: thumbnail: size: [1200, 800] mode: inset # Dual format with client-side detection thumb_jpeg: format: jpeg quality: 80 filters: thumbnail: size: [300, 300] mode: outbound thumb_webp: format: webp quality: 85 filters: thumbnail: size: [300, 300] mode: outbound ``` -------------------------------- ### Configure Crop Filter (YAML) Source: https://github.com/liip/liipimaginebundle/blob/2.x/Resources/doc/filters/sizing.rst Configures the 'crop' filter to perform cropping operations on images. It allows specifying the size of the cropping area and the starting coordinates for the crop. This is useful for extracting specific portions of an image. ```yaml # app/config/config.yml liip_imagine: filter_sets: # name our filter set "my_crop_filter" my_crop_filter: filters: # use and setup the "crop" filter crop: # set the size of the cropping area size: [ 300, 600 ] # set the starting coordinates of the crop start: [ 040, 160 ] ``` -------------------------------- ### Image Post-Processor Configuration (YAML) Source: https://context7.com/liip/liipimaginebundle/llms.txt Configures post-processors to optimize final image binaries, including JPEG and PNG optimization. Supports multiple post-processors chained together for comprehensive optimization. ```yaml liip_imagine: filter_sets: # Optimized JPEG thumbnail optimized_jpeg: quality: 85 filters: thumbnail: size: [800, 600] mode: inset post_processors: jpegoptim: strip_all: true max: 80 progressive: true # Optimized PNG optimized_png: filters: thumbnail: size: [400, 400] mode: inset post_processors: optipng: strip_all: true level: 5 pngquant: quality: "65-80" # Multiple post-processors chain fully_optimized: filters: thumbnail: size: [600, 400] mode: outbound strip: ~ post_processors: jpegoptim: strip_all: true max: 75 progressive: true optipng: level: 7 ``` -------------------------------- ### Configure FileSystemLoader Locator in LiipImagineBundle Source: https://github.com/liip/liipimaginebundle/blob/2.x/UPGRADE.md Configure the resource locator for the FileSystemLoader in LiipImagineBundle. You can choose between the default secure 'filesystem' locator or the older 'filesystem_insecure' locator, which is not recommended due to potential security risks with symbolic links. ```yaml liip_imagine: loaders: default: filesystem: locator: filesystem ``` ```yaml liip_imagine: loaders: default: filesystem: locator: filesystem_insecure ``` -------------------------------- ### CacheManager Service Usage (PHP) Source: https://context7.com/liip/liipimaginebundle/llms.txt Demonstrates programmatic access to LiipImagineBundle's CacheManager service in PHP. Shows how to generate browser paths for filtered images, check cache status, resolve cached URLs, and clear cached images. ```php getBrowserPath( '/uploads/' . $image, 'my_thumb' ); } // Check if image is already cached $isCached = $cacheManager->isStored('/uploads/photo1.jpg', 'my_thumb'); // Resolve cached image URL directly if ($isCached) { $directUrl = $cacheManager->resolve('/uploads/photo1.jpg', 'my_thumb'); } // Generate URL with runtime configuration $customUrl = $cacheManager->getBrowserPath( '/uploads/photo1.jpg', 'my_thumb', ['thumbnail' => ['size' => [200, 200]]] ); return $this->render('gallery.html.twig', [ 'thumbnails' => $thumbnails, ]); } #[Route('/clear-cache/{image}', name: 'clear_image_cache')] public function clearCache(CacheManager $cacheManager, string $image): Response { // Remove cached versions for specific path and filter $cacheManager->remove('/uploads/' . $image, 'my_thumb'); // Remove all cached versions for a path (all filters) $cacheManager->remove('/uploads/' . $image); // Remove all cached images for a filter $cacheManager->remove(null, 'my_thumb'); return new Response('Cache cleared'); } } ``` -------------------------------- ### Set Custom MozJPEG Binary Path (YAML) Source: https://github.com/liip/liipimaginebundle/blob/2.x/Resources/doc/post-processors/jpeg-moz.rst This configuration demonstrates how to specify a custom path for the 'cjpeg' executable if it's not located at the default '/opt/mozjpeg/bin/cjpeg'. This is necessary when the MozJPEG binary is installed in a non-standard location on your system. ```yaml # app/config/config.yml parameters: liip_imagine.mozjpeg.binary: /your/custom/path/to/cjpeg ``` -------------------------------- ### Configure OptiPNG Post-Processor in Filter Set (YAML) Source: https://github.com/liip/liipimaginebundle/blob/2.x/Resources/doc/post-processors/png-opti.rst This configuration snippet demonstrates how to add the OptiPNG post-processor to a filter set named 'my_thumb'. It enables metadata stripping and sets the optimization level to 5. This is useful for reducing PNG file sizes without losing quality. ```yaml # app/config/config.yml liip_imagine: filter_sets: my_thumb: filters: thumbnail: { size: [120, 90], mode: outbound } background: { size: [124, 94], position: center, color: '#000' } post_processors: optipng: { strip_all: true, level: 5 } ``` -------------------------------- ### Specify Custom JPEG Optim Binary Path in YAML Source: https://github.com/liip/liipimaginebundle/blob/2.x/Resources/doc/post-processors/jpeg-optim.rst This configuration demonstrates how to specify a custom path for the jpegoptim executable if it's not located at the default '/usr/bin/jpegoptim'. This is crucial for systems where jpegoptim is installed in a non-standard location. ```yaml # app/config/config.yml parameters: liip_imagine.jpegoptim.binary: /your/custom/path/to/jpegoptim ```