Risuai 0.6.3 first commit

This commit is contained in:
kwaroran
2023-05-07 12:41:45 +09:00
parent 50e5e1d917
commit 2c5c7d2694
98 changed files with 15070 additions and 0 deletions

36
src/ts/exif.ts Normal file
View File

@@ -0,0 +1,36 @@
import extract from 'png-chunks-extract';
import encode from 'png-chunks-encode';
import textKey from 'png-chunk-text'
export const PngMetadata = {
write: (pngBuffer: Uint8Array, metadata: Record<string, string>): Buffer => {
let chunks:{
name:string
data:Uint8Array
}[] = extract(Buffer.from(pngBuffer));
chunks = chunks.filter((v) => {
return v.name.toLocaleLowerCase() !== 'text'
})
for (const key in metadata) {
const value = metadata[key];
chunks.splice(-1, 0, textKey.encode(key, value))
}
const encoded = encode(chunks);
return encoded
},
filter: (pngBuffer: Uint8Array) => {
let chunks:{
name:string
data:Uint8Array
}[] = extract(Buffer.from(pngBuffer));
chunks = chunks.filter((v) => {
return v.name.toLocaleLowerCase() !== 'text'
})
const encoded = encode(chunks);
return encoded
}
}