Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement: URL based image manipulation with parameters #1151

Closed
cord opened this issue May 5, 2022 · 1 comment
Closed

Improvement: URL based image manipulation with parameters #1151

cord opened this issue May 5, 2022 · 1 comment

Comments

@cord
Copy link

cord commented May 5, 2022

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.

@cord
Copy link
Author

cord commented May 6, 2022

PR with solution:

Intervention/imagecache#126

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants