Buckets:
| import imagemin from "imagemin"; | |
| import imageminJpegtran from "imagemin-jpegtran"; | |
| import type { ImageProps } from "./types"; | |
| const cache = new Map<ImageProps, string>(); | |
| export default async function getBase64ImageUrl( | |
| image: ImageProps, | |
| ): Promise<string> { | |
| let url = cache.get(image); | |
| if (url) { | |
| return url; | |
| } | |
| const response = await fetch( | |
| `https://res.cloudinary.com/${process.env.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME}/image/upload/f_jpg,w_8,q_70/${image.public_id}.${image.format}`, | |
| ); | |
| const buffer = await response.arrayBuffer(); | |
| const minified = await imagemin.buffer(Buffer.from(buffer), { | |
| plugins: [imageminJpegtran()], | |
| }); | |
| url = `data:image/jpeg;base64,${Buffer.from(minified).toString("base64")}`; | |
| cache.set(image, url); | |
| return url; | |
| } | |
Xet Storage Details
- Size:
- 782 Bytes
- Xet hash:
- 82f4c54b2cfddc2da81ae3b8b2efde8d0ba2a3894d27bdaa79030c84663403a9
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.