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

[5.x] Ability to set custom Glide hash #9918

Merged
merged 5 commits into from
Apr 17, 2024
Merged

[5.x] Ability to set custom Glide hash #9918

merged 5 commits into from
Apr 17, 2024

Conversation

jasonvarga
Copy link
Member

@jasonvarga jasonvarga commented Apr 17, 2024

Alternate solution to #9781.

This PR lets you customer the unique hash in Glide-generated files.

By default, the hash is just literally just a md5 hash of the manipulation parameters.

You may want to customize it to make it more human readable for debugging or QA purposes as explained in #9781 or just because you prefer it aesthetically.

You can do this in your AppServiceProvider:

public function register()
{
    $this->app->booting(function () {
        Glide::generateHashUsing(function (string $source, array $params) {
            return collect($params)
                ->sortKeys()
                ->map(fn ($value, $param) => "$param-$value")
                ->join('-');
        });
    });
}

When generating a glide image like this:

{{ glide:myimage width="100" height="50" fit="crop" quality="50" }}

normally it would be generated to a path like this:

containers/assets/path/to/image.jpg/0638baede3a7fc1a91f605e095ab74cc/image.jpg

but with the custom closure it would get generated to this:

containers/assets/path/to/image.jpg/fit-crop-h-50-q-50-w-100/image.jpg

This PR also just does some minor cleanup and refactoring of the cachePath method.

@jasonvarga jasonvarga merged commit 45afdc4 into master Apr 17, 2024
32 checks passed
@jasonvarga jasonvarga deleted the custom-glide-hash branch April 17, 2024 15:10
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

Successfully merging this pull request may close these issues.

1 participant