TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

A new protocol and tool for PNG file attachments

61 点作者 grep_it超过 3 年前

5 条评论

mrspuratic超过 3 年前
PlantUML does almost exactly this for PNG and SVG, it embeds a (post-processed) copy of the input as an iTXt chunk or SGML comment respectively. It can be recovered from those output formats with plantuml's "-metadata" option. Note post-processed: if you use the "!include" extension (for sprites or other reasons) then the saved content won't exactly match the input, but for simple diagrams it's ideal.
jf超过 3 年前
I’ve spent a lot of time thinking about this because of the Playable Quotes [0] project that I worked on with @rndmcnlly.<p>First off, I love embedding data into images. It’s surprising how useful it is to do this! The main reason that I like embedding data into an image is because you get a “thumbnail” essentially for free.<p>In the future, I hope to see a more widespread use of this technique, especially for images that are the output of a set of data. Imagine a chart with the source data embedded into it! Or an SVG embedded in a PNG.<p>This is what we did for Playable Quotes, each quote is a PNG of the framebuffer at the time the quote was started. All of the data needed to play that moment in the game is embedded into the PNG.<p>That said, there are at least three main approaches that can be used to embed data into a PNG. Each has various trade offs:<p>The approaches are as follows: 1: Concatenate the PNG with a ZIP file 2: Use PNG chunks (this is what is done in the article) 3: Embed data using a stenography<p>Here are the pros and cons of each approach:<p>Option 1: Concatenate the PNG with a ZIP file<p>This is a clever technique because (in short) PNGs have length information in them and zip software will attempt to read files from the end of the file if they can’t read from the start.<p>Pros:<p>- Super easy to do: “cat original.png file.zip &gt; new.png”<p>- Easy to work with. You can extract data by using the “zip” command or renaming the new.png to new.zip<p>Cons:<p>- The data is lost when sharing the image. Most image hosts and even some chat programs will strip out the zip data from the image.<p>Option 2: Use PNG chunks (this is what is done in the article)<p>This approach is nice and clean, as the PNG specification explicitly allows for this. In essence, a PNG is a little key&#x2F;value database where the keys are four ASCII printable bytes.<p>Pros:<p>- Complies with the PNG standard<p>- Data is usually maintained, but not always!<p>Cons:<p>- Requires special tooling to use. Standard PNG command line tools don’t offer easy ways to get chunk information out of PNGs<p>- The extra chunks are SOMETIMES removed. Especially by services like Twitter which will try and optimize the images before hosting them<p>Option 3: Embed data using a stenography<p>This is the approach that PICO-8 uses for its game “cartridges” and what we ultimately used for Playable Quotes<p>Pros:<p>- The most durable way to keep the data attached to the image<p>Cons:<p>- The amount of data you can store is limited by the size of the image<p>- Special tooling is needed to extract the data<p>In general, my personal favorite is option 1, as it is the most useful. However, it’s sadly not a practical solution to use in a world where the tools we use to share images (Twitter, Imgur, etc) modify the images in transit.<p>Footnotes:<p>0: <a href="https:&#x2F;&#x2F;tenmile.quote.games" rel="nofollow">https:&#x2F;&#x2F;tenmile.quote.games</a>
评论 #29754976 未加载
评论 #29756236 未加载
评论 #29755490 未加载
trulyme超过 3 年前
&gt; As prior art, there’s a draw.io&#x2F;diagrams.net format which embeds a source string without file name. The source string is encoded in base64 (i.e. unconstrained by PNG), wrapped in XML, then incorrectly encoded as an iTXt chunk.<p>Anyone know what might be incorrect about draw.io iTXt chunk usage?
评论 #29756995 未加载
xg15超过 3 年前
So my takeaway: PNG should be seen as a container format with special support for images, rather than an image format.
tragictrash超过 3 年前
<a href="https:&#x2F;&#x2F;xkcd.com&#x2F;927&#x2F;" rel="nofollow">https:&#x2F;&#x2F;xkcd.com&#x2F;927&#x2F;</a><p>Couldn&#x27;t help it! Project looks super interesting!