Skip to content

Commit f2cb063

Browse files
committed
docs: add usage with CDNs and error handling
1 parent c7643e4 commit f2cb063

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

README.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,15 @@ php artisan vendor:publish --tag="image-transform-url-config"
4040

4141
## Usage
4242

43-
1. Configure the package via `config/image-transform-url.php` to set your `public_path`, from where you want to transform the images.
43+
1. Configure the package via `config/image-transform-url.php` to set your [`public_path`](https://laravel.com/docs/12.x/helpers#method-public-path) directory, from where you want to transform the images.
44+
It is recommended to use a dedicated directory for your images in order to have a separation of concerns.
4445

4546
2. Test your first image transformation:
4647

4748
Use the following URL format to transform your images:
4849

4950
```
50-
http://<domain>/<route-prefix>/<options>/<path-to-your-image.<extension>>
51+
http://<domain>/<route-prefix>/<options>/<path-to-your-image.<jpg|jpeg|png|gif|webp>>
5152
```
5253

5354
for example:
@@ -97,6 +98,38 @@ To force a revalidation, you can either:
9798
3. change the version number (integer) in the options (e.g. `version=2`)
9899
4. or flush the entire cache of your application using the `php artisan cache:clear` command.
99100

101+
## Usage with CDNs
102+
103+
This package is designed to work seamlessly with CDNs like Cloudflare, BunnyCDN, and others.
104+
105+
The most important configuration is the [`Cache-Control`](https://developer.mozilla.org/de/docs/Web/HTTP/Reference/Headers/Cache-Control) header, which you can customize to your liking in the `image-transform-url.php` configuration file.
106+
107+
## Error Handling
108+
109+
The route handler of this package is designed to be robust against invalid options, paths and file names, while also not exposing additional information of your applications public directory structure.
110+
111+
This is why the route handler will return a `404` response if:
112+
113+
- a requested image does not existn at the specified path
114+
- the requested image is not a valid image file
115+
- the provided options are not in the correct format (`key=value`, no trailing comma, etc.)
116+
117+
The only other HTTP error that can be returned is a `429` response, which indicates that the request was rate-limited.
118+
119+
If parts of the given route options are invalid, the route handler will ignore them and only apply the valid options.
120+
121+
Example:
122+
123+
```
124+
http://localhost:8000/image-transform/width=250,quality=foo,format=webp/example.jpg
125+
```
126+
127+
will be processed as:
128+
129+
```
130+
http://localhost:8000/image-transform/width=250,format=webp/example.jpg
131+
```
132+
100133
## Testing
101134

102135
```bash

0 commit comments

Comments
 (0)