WireViz icon indicating copy to clipboard operation
WireViz copied to clipboard

Embed YAML data into PNG

Open jacobian91 opened this issue 3 years ago • 6 comments

Is a solution for #233.

  • Saves YAML data to zTXT chunk of PNGs (note: It does not distinguish between prepended file and input file)
  • Allows WireViz to use a PNG as the input file.
  • If the input file is a PNG, a YAML file is created as one of the outputs. Which can be run again by standard WireViz.

jacobian91 avatar Jun 07 '21 00:06 jacobian91

I changed the argparse types to come in as pathlib.Path object types to shortcut some of the conversion that would have to otherwise be done in each of the functions.

jacobian91 avatar Aug 23 '21 20:08 jacobian91

A thought with regards to the implementation it might be worth either putting this capability behind a command line option, adding a command line option to not add the yaml data into the png (depending on the preference for weither to enable by default or not) or otherwise having a way to get an ouptut without the input embedded.

The reasons I can think of for not wanting to add the input into the png are.

  • Keeping othersise unexpected/sensitive data out of a diagram output e.g. data from the prepend not used in the diagram or in comments.
  • Avoiding the png file size increase, although probably not a significant concern unless a long prepend file is used.

Another soloution for both of these would be to trim down/regenerate the yaml added to the png to only that which is needed to generate the diagram but that feels like it could be quite a complicated thing to do.

Tyler-Ward avatar Aug 23 '21 22:08 Tyler-Ward

@Tyler-Ward, really good points, I hadn't thought of those aspects.

Avoiding the png file size increase, although probably not a significant concern unless a long prepend file is used.

A good thing to check, I just ran it with a 4KB prepend & 3.2KB diagram file. The ending png is 213KB with the data, or 211KB without the data. The size difference I'm assuming is the compressed state of the yaml, which results from the line: txt.add_itxt('yaml', yaml_input,zip=True.

Keeping otherwise unexpected/sensitive data out of a diagram output e.g. data from the prepend not used in the diagram or in comments.

I think that is a good point, I'll leave that up to @formatc1702 for comment. I can certainly implement that, but the questions would be:

  1. Do you want to allow 'source' to be distributed or not, and are there licensing preferences that come into play here?
  2. If you do want the option, what would you like the default behavior to be? I'm in favor of default being to share the source. I've lost source files before and having this be an automatic backup is certainly helpful.

jacobian91 avatar Aug 23 '21 23:08 jacobian91

The other formats, SVG & HTML also could incorporate these but those implementations are a bit more straightforward because they could just be added as comments if desired, and would be able to be just copy/pasted instead of needing to be read by the library. But since those will not have a compression option built-in, the file size will more likely be 1:1 increase by adding the data.

jacobian91 avatar Aug 23 '21 23:08 jacobian91

Update: Rebased on the latest dev version for easier merging

jacobian91 avatar Jan 08 '22 20:01 jacobian91

@Tyler-Ward I just added a command line argument to 'conceal-input' so that this feature can be turned off.

jacobian91 avatar Apr 11 '23 16:04 jacobian91