Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【drawio探秘】导入drawio输出的png图片可以二次编辑 #78

Open
Topppy opened this issue Dec 30, 2022 · 0 comments
Open

【drawio探秘】导入drawio输出的png图片可以二次编辑 #78

Topppy opened this issue Dec 30, 2022 · 0 comments
Milestone

Comments

@Topppy
Copy link
Owner

Topppy commented Dec 30, 2022

猜测思路:

  1. drawio保存时:png图片中额外保存了xml格式的图表信息,
  2. drawio导入自己导出的png图片的时候,解析xml数据并替换png绘制图表到工作区

在阅读到这篇文章后由了验证的方法

[PNG文件格式详解](https://blog.mythsman.com/post/5d2d62b4a2005d74040ef7eb/)

image

首先使用工具https://www.nayuki.io/page/png-file-chunk-inspector 解码分析png的数据

image

可以看到文本信息数据块tEXt(textual data)内有xml数据,

我们复制出来Text string的值,经过decodeURIComponent处理后的到

image

这段应该就是drawio保存的图表信息

如何实现读取和写入

如果需要使用 nodejs 对指定区进行修改和提取,则可以利用 [png-chunks-encode](https://www.npmjs.com/package/png-chunks-encode)
 和 [png-chunks-extract](https://www.npmjs.com/package/png-chunks-encode)

  • 读取本地文件
  • 提取tEXtchunk内容
  • 修改并写入png
  • 保存为png图片

DEMO

https://codesandbox.io/s/magicpng-y27un0

附录

xml在线format:https://jsonformatter.org/xml-editor

pngchunk分析:https://www.nayuki.io/page/png-file-chunk-inspector

pngcheck:

[pngcheck Home Page](http://www.libpng.org/pub/png/apps/pngcheck.html)

png文件格式详解:https://blog.mythsman.com/post/5d2d62b4a2005d74040ef7eb/

@Topppy Topppy added this to the publish milestone Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant