Skip to content

Commit 139ddca

Browse files
committed
Updated README
1 parent 06866ff commit 139ddca

File tree

1 file changed

+94
-9
lines changed

1 file changed

+94
-9
lines changed

README.md

Lines changed: 94 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ Type: CommaDelimitedList
7575

7676
Default: empty string
7777

78-
A comma separated list with allowed pixel densities - modified `pd`.
78+
A comma-separated list with allowed pixel densities - modified `pd`.
7979
Requests are validated against this list only if the list is not empty. For example `1,2,3`.
8080

8181
#### AllowedResolutions
8282
Type: CommaDelimitedList
8383

8484
Default: empty string
8585

86-
A comma separated list with allowed pixel resolutions - modifiers `w` and `h`.
86+
A comma-separated list with allowed pixel resolutions - modifiers `w` and `h`.
8787
Requests are validated against this list only if the list is not empty.
8888
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.
8989

@@ -92,7 +92,7 @@ Type: CommaDelimitedList
9292

9393
Default: empty string
9494

95-
A comma separated list with allowed qualities - modifier `q`.
95+
A comma-separated list with allowed qualities - modifier `q`.
9696
Requests are validated against this list only if the list is not empty. For example: `80,90,100`.
9797

9898
#### EncodeQuality
@@ -102,19 +102,19 @@ Default: `90`
102102

103103
An encode quality for cached images.
104104

105-
#### SourceBucketPostfix
105+
#### SourceBucketName
106106
Type: String
107107

108-
Default: `source`
108+
Default: `image-storage-source`
109109

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.
111111

112-
#### CacheBucketPostfix
112+
#### CacheBucketName
113113
Type: String
114114

115-
Default: `cache`
115+
Default: `image-storage-cache`
116116

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.
118118

119119
#### NoImages
120120
Type: CommaDelimitedList
@@ -131,3 +131,88 @@ Default: empty string
131131

132132
Named patterns for no-images in format `name::pattern`.
133133
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:
166+
167+
```shell
168+
CloudFormation outputs from deployed stack
169+
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
170+
Outputs
171+
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
172+
...
173+
174+
Key CacheBucketDistribution
175+
Description CloudFront URL for cached images - use this URL for image requests
176+
Value https://{HASH}.cloudfront.net
177+
178+
...
179+
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
180+
181+
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:
207+
208+
- NoImages - `default::noimage/default,user::noimage/user`
209+
- NoImagePatterns - `user::^userAvatar\/`
210+
211+
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
218+
```

0 commit comments

Comments
 (0)