diff --git a/README.md b/README.md index 6c3b0d3..491b269 100644 --- a/README.md +++ b/README.md @@ -147,7 +147,15 @@ This will **empty the entire Glide cache**. You can choose to put this in your d ## Glide Configuration -Currently, the package **does not provide configuration** options and it just assumes **sensible defaults**. +Currently, the package **does not provide advanced configuration** options and it just assumes **sensible defaults**. + +If you want to modify the basic configuration values, you can publish the config file: + +```bash +php artisan vendor:publish --tag=glide-config +``` + +After publishing, you can modify the configuration in `config/glide.php`. Since it is geared at auto-generating versions for static images, it will **assume** the `public_path()`/`asset()` as root folder for the images. diff --git a/config/glide.php b/config/glide.php index 4cb642d..1b22e45 100644 --- a/config/glide.php +++ b/config/glide.php @@ -9,6 +9,29 @@ */ 'default_source_disk' => null, + 'route' => [ + /** + * The domain that will be used to generate the Glide URLs. + */ + 'domain' => null, + + /** + * Whether the generated Glide URLs should be signed. + * For some browsers this differing query string + * might prevent browser caching of the image, + * but major browsers appear to handle fine. + */ + 'signed' => false, + ], + + /** + * By default, images receive a `max-width: {originalImageWidth}` rule, + * so that CSS will not upscale them beyond their original width. This + * can be overridden on a per-image basis using the `grow` function + * parameter. However, it can also be configured globally here. + */ + 'grow' => false, + /** * The default image scales to generate. */ @@ -30,21 +53,6 @@ 10000, ], - 'route' => [ - /** - * The domain that will be used to generate the Glide URLs. - */ - 'domain' => null, - - /** - * Whether the generated Glide URLs should be signed. - * For some browsers this differing query string - * might prevent browser caching of the image, - * but major browsers appear to handle fine. - */ - 'signed' => false, - ], - /** * By default, upscaling is enabled up to 2x the original image size. * This is due to Retina / HiDPI-displays, where it can be crisper diff --git a/src/GlideImageGenerator.php b/src/GlideImageGenerator.php index 81e6f64..52b50ac 100644 --- a/src/GlideImageGenerator.php +++ b/src/GlideImageGenerator.php @@ -16,10 +16,12 @@ class GlideImageGenerator { - public function src(string $path, ?int $maxWidth = null, ?string $sizes = null, bool $lazy = true, bool $grow = false, ?string $disk = null): ComponentAttributeBag + public function src(string $path, ?int $maxWidth = null, ?string $sizes = null, bool $lazy = true, ?bool $grow = null, ?string $disk = null): ComponentAttributeBag { $attributes = new ComponentAttributeBag(); + $grow = $grow ?? config('glide.grow'); + $isGlideSupported = $this->isGlideSupported($path); $attributes->setAttributes([