-
Notifications
You must be signed in to change notification settings - Fork 2
Refactored Image Generation #20
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
Conversation
Can we do something about this so it stores it to the exact path we've requested, this way images on the page won't constantly have to go through php and Laravel once the image has been generated |
Why not use the path of where the file is stored as route? Then if there is a file at for example I meant to press request changes but i misclicked 😛 |
The resized images are now saved at the same path as their corresponding route. Updated route structure: For example, a resized image would now be stored at: This approach maintains compatibility with Statamic's cache_path configuration (set to 'public/img'), while providing a more consistent storage pattern. |
…ve into feature/resizer-refactor
src/Controllers/ImageController.php
Outdated
$asset = AssetFacade::findByUrl(Str::start($file, '/')); | ||
$this->asset = $asset; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can directly set $this->asset
here, i think the typehint in the comment is not needed then too
/** @var ?Asset $asset */ | ||
$asset = AssetFacade::findByUrl(Str::start($file, '/')); | ||
$this->asset = $asset; | ||
$this->params = ['s' => $signature, 'preset' => $preset, 'fit' => $fit, 'format' => $format]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe after merge; We can create a ImageRequest to validate the parameters, now it will probably have an empty string in one of these variables if not filled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If one of these parameters is not filled it means the given path is not right, which already results in a 404.
Haven't been able to get this to go wrong at least.
This PR changes the way images are served to the browser. Images are now delivered via routes, allowing them to be generated on-demand rather than during the initial page load. This approach improves overall page loading times.
The routes used for the srcset are structured as follows:
storage/glide-image/{preset}/{fit}/{signature}/{file}{format}
For example:
storage/glide-image/2xl/contain/f26f2e8e2d900e81b91bb236a451a196/assets/bierbekers-bedrukken-1685894250.jpg.webp
The signature is generated based on the asset path and the provided parameters.
Glide still handles the image generation itself, so the underlying generation behavior remains unchanged. Generated images are stored in the public folder, for example:
/img/containers/assets/xxx.jpg/1a5520e23a7f46fcc39e1e75c2c840f0/xxx.webp