changed metadata output

This commit is contained in:
Gabriel Gomes 2025-03-29 22:02:22 +00:00
parent c8ccdf3716
commit 770f44019a
3 changed files with 33 additions and 3 deletions

View file

@ -14,14 +14,30 @@ import { encode, decode } from "./encode";
export const getMetadataChunk = async (
blob: Blob,
): Promise<{ keyword: string; text: string } | null> => {
): Promise<{
keyword: string;
text: string;
compressionFlag?: boolean;
compressionMethod?: number;
languageTag?: string;
translatedKeyword?: string;
} | null> => {
const chunks = decodePng(new Uint8Array(await blobToArrayBuffer(blob)));
const iTXtChunk = chunks.find((chunk) => chunk.name === "iTXt");
if (iTXtChunk) {
try {
const decoded = decodeITXt(iTXtChunk.data);
return { keyword: decoded.keyword, text: decoded.text };
console.log("Decoded iTXt chunk:", decoded);
return {
keyword: decoded.keyword,
text: decoded.text,
compressionFlag: decoded.compressed,
compressionMethod: decoded.compressedMethod,
languageTag: decoded.language || "",
translatedKeyword: decoded.translated || ""
};
} catch (error) {
console.error("Failed to decode iTXt chunk:", error);
}
@ -45,7 +61,7 @@ export const encodePngMetadata = async ({
useITXt?: boolean;
}) => {
const chunks = decodePng(new Uint8Array(await blobToArrayBuffer(blob)));
debugger;
const filteredChunks = chunks.filter(
(chunk) =>
!(chunk.name === "tEXt" &&

View file

@ -51,6 +51,8 @@ declare module "png-chunk-itxt" {
function decode(data: Uint8Array): {
keyword: string;
text: string;
compressed?: boolean;
compressedMethod?: number;
language?: string;
translated?: string;
};

View file

@ -3882,6 +3882,11 @@ binary-extensions@^2.0.0:
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.3.0.tgz#f6e14a97858d327252200242d4ccfe522c445522"
integrity sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw==
binary-parser@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/binary-parser/-/binary-parser-2.2.1.tgz#4edc6da2dc56db73fa5ba450dfe6382ede8294ce"
integrity sha512-5ATpz/uPDgq5GgEDxTB4ouXCde7q2lqAQlSdBRQVl/AJnxmQmhIfyxJx+0MGu//D5rHQifkfGbWWlaysG0o9NA==
bl@^4.0.3:
version "4.1.0"
resolved "https://registry.yarnpkg.com/bl/-/bl-4.1.0.tgz#451535264182bec2fbbc83a62ab98cf11d9f7b3a"
@ -7919,6 +7924,13 @@ pkg-dir@4.2.0:
dependencies:
find-up "^4.0.0"
png-chunk-itxt@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/png-chunk-itxt/-/png-chunk-itxt-1.0.0.tgz#4652547b7c88d512337599e422b7431f2c234355"
integrity sha512-/1gTTBlIBUL47FS1wXI5oW5zidHge1Lwn+w4WNsnTc6wu1i82l63hwz0mgw1x2eYFH4iYkHkmKH0FHoHYMmjig==
dependencies:
binary-parser "^2.2.1"
png-chunk-text@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/png-chunk-text/-/png-chunk-text-1.0.0.tgz#1c6006d8e34ba471d38e1c9c54b3f53e1085e18f"