fukuchi / libqrencode

A fast and compact QR Code encoding library
https://fukuchi.org/works/qrencode/
GNU Lesser General Public License v2.1
2.58k stars 599 forks source link

Embedding the input string to PNG, SVG and EPS #20

Open fukuchi opened 12 years ago

fukuchi commented 12 years ago

David Dahl suggests:

Another item I have been thinking about is the possibility of including the input string's value as metadata in the image file. It may be advantageous to include this as a tEXt or iTXt chunk with a "comment" key in a PNG, or a <desc>...</desc> or <title>...</title> pair in an SVG.

While I like this suggestion, the implementation seems to be not simple: 1) How to embed binary (8-bit) data? 2) Embedding text data to SVG/EPS may require sanitizing.

Your comments are welcome.

Oblomov commented 10 years ago

This is something I have been thinking about as well, although my initial plan was to add the original text as comment (in SVG as well). Using a title tag would definitely make more sense though.

For SVG, one could resort to plopping the thing in a CDATA: the only care that needs to be taken then is that the (unlikely) sequence ]]> must be split across two CDATA sections, which is very easy to do. The only thing that should be ensured is that the character encoding of the XML is set correctly (so, shift_jis or iso-8859-1 as appropriate).

For EPS, the text would need to go in some comment, so the only escaping that would be needed is that of newlines, probably, although I' d have to refresh my knowledge of EPS and the DSC to be sure about that.

For PNG with arbitrary data, one could encode the thing with base64 before stuffing it in a text chunk if it contains anything that is not a printable latin1 character.

I'll see if I can cook up something for the SVG part. EDIT: I've started working on the feature in my embed-intext branch.