daasd commited on
Commit
d8ec177
·
1 Parent(s): fc68712

Update PNG_info_web.js

Browse files
Files changed (1) hide show
  1. PNG_info_web.js +23 -18
PNG_info_web.js CHANGED
@@ -259,31 +259,36 @@
259
  let shadowRoot = null;
260
  let result = {};
261
  let png_info_blob = {};
262
- //readNovelAITag源码参考于秋叶大佬
263
  const readNovelAITag = async (file) => {
264
- const buf = await file.arrayBuffer();
265
  let chunks = [];
 
266
  try {
267
- chunks = extractChunks(new Uint8Array(buf));
268
- } catch (err) {
269
- return chunks;
270
- }
271
- let textChunks = chunks.filter(function (chunk) {
272
- return chunk.name === "tEXt" || chunk.name === "iTXt";
273
  });
274
  textChunks = textChunks.map(function (chunk) {
275
- if (chunk.name === "iTXt") {
276
- let data = chunk.data.filter((x) => x != 0x0);
277
- let txt = new TextDecoder().decode(data);
278
- return {
279
- keyword: "信息",
280
- text: txt.slice(10),
281
- };
282
- }
283
- return decode(chunk.data);
284
  });
285
  return textChunks;
286
- };
 
 
 
 
 
 
 
287
 
288
  //dom转blob
289
  async function convertDomImageToBlob(imageElement) {
 
259
  let shadowRoot = null;
260
  let result = {};
261
  let png_info_blob = {};
262
+ //readNovelAITag函数参考于秋叶大佬并进行了优化
263
  const readNovelAITag = async (file) => {
 
264
  let chunks = [];
265
+ let textChunks = [];
266
  try {
267
+ const buf = await file.arrayBuffer();
268
+ chunks = extractChunks(new Uint8Array(buf));
269
+ textChunks = chunks.filter(function (chunk) {
270
+ return chunk.name === "tEXt" || chunk.name === "iTXt";
 
 
271
  });
272
  textChunks = textChunks.map(function (chunk) {
273
+ if (chunk.name === "iTXt") {
274
+ let data = chunk.data.filter((x) => x != 0x0);
275
+ let txt = new TextDecoder().decode(data);
276
+ return {
277
+ keyword: "信息",
278
+ text: txt.slice(10),
279
+ };
280
+ }
281
+ return decode(chunk.data);
282
  });
283
  return textChunks;
284
+ } catch (err) {
285
+ console.error(err);
286
+ } finally {
287
+ chunks = null;
288
+ textChunks = null;
289
+ }
290
+ return [];
291
+ };
292
 
293
  //dom转blob
294
  async function convertDomImageToBlob(imageElement) {