Risuai 0.6.3 first commit
This commit is contained in:
36
src/ts/exif.ts
Normal file
36
src/ts/exif.ts
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user