mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
changed metadata output
This commit is contained in:
parent
c8ccdf3716
commit
770f44019a
3 changed files with 33 additions and 3 deletions
|
@ -14,14 +14,30 @@ import { encode, decode } from "./encode";
|
||||||
|
|
||||||
export const getMetadataChunk = async (
|
export const getMetadataChunk = async (
|
||||||
blob: Blob,
|
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 chunks = decodePng(new Uint8Array(await blobToArrayBuffer(blob)));
|
||||||
|
|
||||||
const iTXtChunk = chunks.find((chunk) => chunk.name === "iTXt");
|
const iTXtChunk = chunks.find((chunk) => chunk.name === "iTXt");
|
||||||
|
|
||||||
if (iTXtChunk) {
|
if (iTXtChunk) {
|
||||||
try {
|
try {
|
||||||
const decoded = decodeITXt(iTXtChunk.data);
|
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) {
|
} catch (error) {
|
||||||
console.error("Failed to decode iTXt chunk:", error);
|
console.error("Failed to decode iTXt chunk:", error);
|
||||||
}
|
}
|
||||||
|
@ -45,7 +61,7 @@ export const encodePngMetadata = async ({
|
||||||
useITXt?: boolean;
|
useITXt?: boolean;
|
||||||
}) => {
|
}) => {
|
||||||
const chunks = decodePng(new Uint8Array(await blobToArrayBuffer(blob)));
|
const chunks = decodePng(new Uint8Array(await blobToArrayBuffer(blob)));
|
||||||
|
debugger;
|
||||||
const filteredChunks = chunks.filter(
|
const filteredChunks = chunks.filter(
|
||||||
(chunk) =>
|
(chunk) =>
|
||||||
!(chunk.name === "tEXt" &&
|
!(chunk.name === "tEXt" &&
|
||||||
|
|
2
packages/excalidraw/global.d.ts
vendored
2
packages/excalidraw/global.d.ts
vendored
|
@ -51,6 +51,8 @@ declare module "png-chunk-itxt" {
|
||||||
function decode(data: Uint8Array): {
|
function decode(data: Uint8Array): {
|
||||||
keyword: string;
|
keyword: string;
|
||||||
text: string;
|
text: string;
|
||||||
|
compressed?: boolean;
|
||||||
|
compressedMethod?: number;
|
||||||
language?: string;
|
language?: string;
|
||||||
translated?: string;
|
translated?: string;
|
||||||
};
|
};
|
||||||
|
|
12
yarn.lock
12
yarn.lock
|
@ -3882,6 +3882,11 @@ binary-extensions@^2.0.0:
|
||||||
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.3.0.tgz#f6e14a97858d327252200242d4ccfe522c445522"
|
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.3.0.tgz#f6e14a97858d327252200242d4ccfe522c445522"
|
||||||
integrity sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw==
|
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:
|
bl@^4.0.3:
|
||||||
version "4.1.0"
|
version "4.1.0"
|
||||||
resolved "https://registry.yarnpkg.com/bl/-/bl-4.1.0.tgz#451535264182bec2fbbc83a62ab98cf11d9f7b3a"
|
resolved "https://registry.yarnpkg.com/bl/-/bl-4.1.0.tgz#451535264182bec2fbbc83a62ab98cf11d9f7b3a"
|
||||||
|
@ -7919,6 +7924,13 @@ pkg-dir@4.2.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
find-up "^4.0.0"
|
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:
|
png-chunk-text@1.0.0:
|
||||||
version "1.0.0"
|
version "1.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/png-chunk-text/-/png-chunk-text-1.0.0.tgz#1c6006d8e34ba471d38e1c9c54b3f53e1085e18f"
|
resolved "https://registry.yarnpkg.com/png-chunk-text/-/png-chunk-text-1.0.0.tgz#1c6006d8e34ba471d38e1c9c54b3f53e1085e18f"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue