move on from custom image optim
This commit is contained in:
		
							
								
								
									
										1175
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										1175
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -47,7 +47,6 @@ | ||||
|     "rollup-plugin-svg": "^2.0.0", | ||||
|     "rollup-plugin-terser": "^7.0.2", | ||||
|     "sapper": "^0.28.10", | ||||
|     "sharp": "^0.26.1", | ||||
|     "svelte": "^3.30.1", | ||||
|     "svelte-check": "^1.1.17", | ||||
|     "svelte-preprocess": "^4.6.1", | ||||
|   | ||||
| @@ -1,46 +0,0 @@ | ||||
| import path from 'path' | ||||
| import sharp from 'sharp' | ||||
|  | ||||
| const outputOptions = { | ||||
|   jpeg: { | ||||
|     quality: 90, | ||||
|     mozjpeg: true, | ||||
|   }, | ||||
|   png: {}, | ||||
|   webp: { | ||||
|     quality: 90, | ||||
|     // lossless: true, | ||||
|   }, | ||||
| } | ||||
| /** | ||||
|  * Transform image into multiple optimized version for web browsing | ||||
|  * Create a optimized image of same filetype and extra `webp` | ||||
|  */ | ||||
| export async function optimizeImage(imgPath: string) { | ||||
|   const imgPathProps = path.parse(imgPath) | ||||
|   const image = sharp(imgPath) | ||||
|   const metadata = await image.metadata() | ||||
|  | ||||
|   const formats = [metadata.format, 'webp'] | ||||
|  | ||||
|   const results = await Promise.all( | ||||
|     formats.map((format) => | ||||
|       image | ||||
|         .toFormat(format, outputOptions[format]) | ||||
|         .resize({ width: 640, height: 640, fit: 'inside' }) | ||||
|         .toFile( | ||||
|           `${path.join(imgPathProps.dir, 'optimized', imgPathProps.name)}.${ | ||||
|             format === 'jpeg' ? 'jpg' : format | ||||
|           }` | ||||
|         ) | ||||
|     ) | ||||
|   ) | ||||
|   console.log(results) | ||||
| } | ||||
|  | ||||
| /** Transform all uploaded images into optimized versions */ | ||||
| // TODO Optimize all uploaded images | ||||
| // Think of a strategy which would be the best | ||||
| // Upload 3MB images to git ? | ||||
| // Have the script be run on the build? or be good person and upload optimized images by yourself? | ||||
| // What about images smaller then 640? they should not be resized right? | ||||
| @@ -1,5 +0,0 @@ | ||||
| import { optimizeImage } from './image-optimization' | ||||
|  | ||||
| const args = process.argv.slice(2) | ||||
|  | ||||
| args.forEach((file) => optimizeImage(file)) | ||||
		Reference in New Issue
	
	Block a user