remove EXIF information from PNG, JPEG and WebP images jsr.io/@mary/exif-rm
typescript jsr
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor: take uint8 as input

Mary 73ecc106 1d705b71

+8 -9
+6 -7
mod.ts
··· 3 3 * @returns A new image buffer with EXIF removed, will return `null` if 4 4 * image is unsupported, or if there's nothing to remove. 5 5 */ 6 - export const remove = (buf: ArrayBuffer): Uint8Array | null => { 7 - const view = new DataView(buf); 8 - const indices: [start: number, end: number][] = []; 6 + export const remove = (buf: Uint8Array): Uint8Array | null => { 7 + const blen = buf.byteLength; 9 8 10 - const blen = view.byteLength; 9 + const view = new DataView(buf.buffer, buf.byteOffset, blen); 10 + const indices: [start: number, end: number][] = []; 11 11 12 12 let start = 0; 13 13 ··· 80 80 return null; 81 81 } 82 82 83 - const uint8 = new Uint8Array(buf); 84 83 const copy = new Uint8Array(indices.reduce((accu, index) => accu + (index[1] - index[0]), blen - start)); 85 84 86 85 copy.set( 87 - uint8.subarray(start), 86 + buf.subarray(start), 88 87 indices.reduce((offset, index) => { 89 - copy.set(uint8.subarray(index[0], index[1]), offset); 88 + copy.set(buf.subarray(index[0], index[1]), offset); 90 89 return offset + (index[1] - index[0]); 91 90 }, 0), 92 91 );
+2 -2
test.ts
··· 4 4 5 5 Deno.test('removes EXIF from JPEG files', async () => { 6 6 const image = await Deno.readFile('./samples/sample.jpg'); 7 - const exifRemoved = remove(image.buffer); 7 + const exifRemoved = remove(image); 8 8 9 9 assert(exifRemoved != null); 10 10 assert(exifRemoved.byteLength === 5480); ··· 12 12 13 13 Deno.test('removes EXIF from PNG files', async () => { 14 14 const image = await Deno.readFile('./samples/sample.png'); 15 - const exifRemoved = remove(image.buffer); 15 + const exifRemoved = remove(image); 16 16 17 17 assert(exifRemoved != null); 18 18 assert(exifRemoved.byteLength === 17638);