You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+94-9Lines changed: 94 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -75,15 +75,15 @@ Type: CommaDelimitedList
75
75
76
76
Default: empty string
77
77
78
-
A commaseparated list with allowed pixel densities - modified `pd`.
78
+
A comma-separated list with allowed pixel densities - modified `pd`.
79
79
Requests are validated against this list only if the list is not empty. For example `1,2,3`.
80
80
81
81
#### AllowedResolutions
82
82
Type: CommaDelimitedList
83
83
84
84
Default: empty string
85
85
86
-
A commaseparated list with allowed pixel resolutions - modifiers `w` and `h`.
86
+
A comma-separated list with allowed pixel resolutions - modifiers `w` and `h`.
87
87
Requests are validated against this list only if the list is not empty.
88
88
For example `300x300,300x,x200` allows requests on images with dimensions `300x300` or with `300` width and calculated height or with `200` height and calculated width.
89
89
@@ -92,7 +92,7 @@ Type: CommaDelimitedList
92
92
93
93
Default: empty string
94
94
95
-
A commaseparated list with allowed qualities - modifier `q`.
95
+
A comma-separated list with allowed qualities - modifier `q`.
96
96
Requests are validated against this list only if the list is not empty. For example: `80,90,100`.
97
97
98
98
#### EncodeQuality
@@ -102,19 +102,19 @@ Default: `90`
102
102
103
103
An encode quality for cached images.
104
104
105
-
#### SourceBucketPostfix
105
+
#### SourceBucketName
106
106
Type: String
107
107
108
-
Default: `source`
108
+
Default: `image-storage-source`
109
109
110
-
A postfix for the Source Bucket's name. Final Bucket's name is in format `{stack name}-{postfix}`.
110
+
A unique Source Bucket's name.
111
111
112
-
#### CacheBucketPostfix
112
+
#### CacheBucketName
113
113
Type: String
114
114
115
-
Default: `cache`
115
+
Default: `image-storage-cache`
116
116
117
-
A postfix for the Cache Bucket's name. Final Bucket's name is in format `{stack name}-{postfix}`.
117
+
A unique Cache Bucket's name.
118
118
119
119
#### NoImages
120
120
Type: CommaDelimitedList
@@ -131,3 +131,88 @@ Default: empty string
131
131
132
132
Named patterns for no-images in format `name::pattern`.
133
133
or example if you define `user::^userAvatar\/` and a path of a requested image will match regex then a no-image named `user` will be returned.
134
+
135
+
## Supported modifiers and image types
136
+
137
+
#### Modifiers
138
+
139
+
| Name | Shortcut | Type | Note |
140
+
| --- | --- | --- | --- |
141
+
| Original | original | - | A modifier without a value, use it if you want to return the original image |
142
+
| Height | h | Integer | Can be restricted by parameter `AllowedResolutions`|
143
+
| Width | w | Integer | Can be restricted by parameter `AllowedResolutions`|
144
+
| Pixel density | pd | Integer\|Float | Can be restricted by parameter `AllowedPixelDensity`|
145
+
| Quality | q | Integer | Can be restricted by parameter `AllowedQualities`|
146
+
| Orientation | o | Integer\|String | Allowed values are `auto, 0, 90, -90, 180, -180, 270, -270`|
147
+
148
+
#### Image types
149
+
150
+
- JPEG - `.jpeg` or `.jpg`
151
+
- Progressive JPEG - `.pjpg`
152
+
- PNG - `.png`
153
+
- GIF - `.gif`
154
+
- WEBP - `.webp`
155
+
156
+
## Usage
157
+
158
+
Generated images are cached in a Cache Bucket. A name of the Cache Bucket that is defined by parameter `CacheBucketName`.
159
+
If some image is requested and the Cache Bucket contains it then the image is returned directly.
160
+
Otherwise a Lambda function is called and it will try to access the image through the Source Bucket (a name is defined by parameter `SourceBucketName`), modify it and save it to the Cache Bucket.
161
+
The Lambda function can return an error 404 or a `no-image` image if some is provided by you.
162
+
163
+
#### What is the URL of my API?
164
+
165
+
After the application will be successfully deployed you will see the application's outputs in the console like this:
Successfully created/updated stack - {STACK_NAME} in {REGION}
182
+
```
183
+
184
+
The value of key `CacheBucketDistribution` is a host URL for your application.
185
+
186
+
#### Simple example
187
+
188
+
Firstly upload any image to the Source Bucket but the name of the object (your image) must be always without a file extension!
189
+
For example if your image is called `picoftheday.jpeg` and you will drop it to the root of the Source Bucket then you must rename it just to `picoftheday`.
190
+
Your image can be placed into any directory of course.
191
+
192
+
Then you can try to request some modifications of the image:
193
+
194
+
```
195
+
https://{HASH}.cloudfront.net/original/picoftheday.jpeg - returns the original image
196
+
https://{HASH}.cloudfront.net/original/picoftheday.png - returns the original image but in a PNG format
197
+
https://{HASH}.cloudfront.net/w:200,h:100,o:90/picoftheday.jpeg - returns an image with dimensions 200x100 and rotated by 90 degrees
198
+
https://{HASH}.cloudfront.net/w:200,h:100,pd:2,q:50/picoftheday.jpeg - returns an image with dimensions 400x200 (because of pixel density) and with output quality 50%
199
+
...
200
+
https://{HASH}.cloudfront.net/picoftheday.jpeg - an error 500, the URL must always contains an modifiers
201
+
https://{HASH}.cloudfront.net/foo/original/bar.jpeg - an error 404, missing object `foo/bar` in the Source Bucket
202
+
```
203
+
204
+
#### Example with NoImages
205
+
206
+
The NoImages are images provided by you that are returned instead of the 404 response if a requested image not found. For example you can configure the parameters `NoImages` and `NoImagePatterns` with this values:
Then upload any images with names `default` and `user` (without file extensions again) into a directory `noimage` in the Source Bucket. So paths to objects will be `noimage/default` and `noimage/user`
212
+
213
+
Then you can try to request some nonexistent images:
214
+
215
+
```
216
+
https://{HASH}.cloudfront.net/foo/bar/w:50/baz.jpeg - an image `noimage/default` with 50px width in JPEG format is returned
217
+
https://{HASH}.cloudfront.net/user/foo/w:50/bar.png - an image `noimage/user` with 50px width in PNG format is returned
0 commit comments