-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.js
More file actions
35 lines (32 loc) · 1.34 KB
/
start.js
File metadata and controls
35 lines (32 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
self.location = {href: import.meta.url};
let mozjpeg = await (await import('./mozjpeg_enc.js')).default({noInitialRun: true});
// let mozjpeg = await (await import('https://esm.sh/gh/GoogleChromeLabs/squoosh/codecs/mozjpeg/enc/mozjpeg_enc.js')).default({noInitialRun: true});
let {decode, encode} = await import('https://esm.sh/gh/fakoua/jpeg.ts/mod.ts');
let {decode: decodeAVIF, encode: encodeAVIF} = await import('https://esm.sh/gh/jamsinclair/jSquash/packages/avif'); // npm:@jsquash/avif
let options = {
quality: 75,
baseline: false,
arithmetic: false,
progressive: true,
optimize_coding: true,
smoothing: 0,
color_space: 3, // MozJpegColorSpace {GRAYSCALE = 1, RGB, YCbCr,}
quant_table: 3,
trellis_multipass: true,
trellis_opt_zero: true,
trellis_opt_table: true,
trellis_loops: 1,
auto_subsample: true,
chroma_subsample: 2,
separate_chroma_quality: false,
chroma_quality: 75,
};
let source = './source';
let destination = './compressed';
for await (let file of Deno.readDir(source + '/')) {
let rawImage = await Deno.readFile(source + '/' + file.name);
let decodedImage = decode(rawImage);
let encodedImage = mozjpeg.encode(decodedImage.data, decodedImage.width, decodedImage.height, options);
Deno.writeFile(destination + '/' + file.name.split(',')[0] + '.jpg', encodedImage);
console.log(file.name);
}