Skip to content

Improvement: URL based image manipulation with parameters #1151

@cord

Description

@cord

Would be great if the package supports flexible resizing, effects etc. through url parameters. This can "almost" be done, but the image cache does not support this:

In short:

Issue: ImageCache does not support url parameters, but takes only filename as cache key

possible solutions:

  • allow to configure custom implementation of ImageCache
  • allow to pass cache key parameters through applyFilter() method

working example for 'dynamic' filter:

    public function applyFilter(Image $image)
    {

        // issue:
        // parameter is not added to cachekey

        // w = width in px
        $width =request()->input('w');
        $quality =request()->input('q') ?? 90;

        $image->resize($width, null, function ($constraint) {
            $constraint->aspectRatio();
        })
            ->encode('jpg', $quality)
        ;
        return $image;
    }

example requests:

  1. generate thumbnail:

http://yourhost.com/{route-name}/original/{file-name}?w=100&q=50

  1. generate preview:

http://yourhost.com/{route-name}/original/{file-name}?w=200&q=90

both urls will return the same cached image (whichever was called first) as the cache key does not support parameters.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions