1- # Images
2-
3- The Epic Stack distinguishes between user images and static app image assets.
4- User images are stored in SQLite along with the rest of the application data,
5- while static images are stored in the [ ../public/img/] ( ../public/img/ ) folder.
6- See the [ images decision doc] ( ./decisions/018-images.md ) for more details.
7-
8- ## User Images
9-
10- User images (uploaded by a user) are stored in SQLite and served via resource
11- routes, for example:
12- [ /resources/user-images/$imageId] ( ../app/routes/resources+/user-images.$imageId.tsx ) .
13-
14- ## Image Optimization
1+ # Image Optimization
152
163The Epic Stack uses [ openimg] ( https://github.com/andrelandgraf/openimg ) to
174optimize images on demand, introduced via
185[ this decision doc] ( ./decisions/039-image-optimization.md ) .
196
20- ### Server Part
7+ ## Server Part
218
229The [ /resources/images] ( ../app/routes/resources+/images.tsx ) endpoint accepts
2310the search parameters ` src ` , ` w ` (width), ` h ` (height), ` format ` , and ` fit ` to
2411perform image transformations and serve optimized variants. The transformations
2512are performed with ` sharp ` , and the optimized images are cached in
26- ` ./data/images ` on the filesystem and via HTTP caching.
13+ ` ./data/images ` on the filesystem and via HTTP caching. All transformations happen
14+ via stream processing, so images are never loaded fully into memory at once.
2715
28- ### Client Part
16+ ## Client Part
2917
3018On the client side, the ` Img ` React component from openimg/react is used to
3119query the [ /resources/images] ( ../app/routes/resources+/images.tsx ) endpoint with
@@ -36,11 +24,11 @@ loading. It also computes `srcset` and `sizes` based on the provided `width` and
3624` height ` props. Use the ` isAboveFold ` prop on the ` Img ` component to priotize
3725images that should load immediately.
3826
39- ### Image Sources
27+ ## Image Sources
4028
4129If you want to add a new image storage location, like an S3 bucket, update the
42- [ /resources/images] ( ../app/routes/resources+/images.tsx ) endpoint and modify the
43- ` getSource ` function to instruct openimg on how to retrieve the source images
44- from the new location. Currently, the endpoint uses fetch requests to retrieve
45- user images from the resource route endpoints and the filesystem to retrieve
46- static application assets from the public and assets folders.
30+ [ /resources/images] ( ../app/routes/resources+/images.tsx ) endpoint and modify
31+ ` getSource ` and ` allowlistedOrigins ` to instruct openimg on how to retrieve the
32+ source images from the new location. Currently, the endpoint uses fetch requests
33+ to retrieve user images from the resource route endpoints and the filesystem to
34+ retrieve static application assets from the public and assets folders.
0 commit comments