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

Embed YAML data into PNG #234

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open

Conversation

jacobian91
Copy link

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.

Copy link
Collaborator

@formatc1702 formatc1702 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your explanation in #233.
I will play around with and think about this feature a bit later.
For now, I'm leaving some comments on the current implementation.
I will come back to this PR once I have time.

with open_file_read(args.prepend_file) as fh:
prepend = fh.read()
yaml_input = prepend + yaml_input
if ".png" in args.input_file:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider using Pathlib's .suffix attribute for checking the file extension.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

yaml_input = prepend + yaml_input
if ".png" in args.input_file:
yaml_input = read_yaml_from_png(args.input_file.replace('.png',''))
with open(args.input_file.replace('.png','_out.yaml'),'w') as fh:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using wv_helper.py's open_file_read() and open_file_write() functions for file access to ensure UTF-8 encoding

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks!

src/wireviz/wireviz.py Outdated Show resolved Hide resolved
src/wireviz/wireviz.py Show resolved Hide resolved
@jacobian91
Copy link
Author

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.

@Tyler-Ward
Copy link
Contributor

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.

@jacobian91
Copy link
Author

jacobian91 commented Aug 23, 2021

@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
Copy link
Author

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.

Jacob Erickson added 3 commits January 8, 2022 12:03
@jacobian91
Copy link
Author

Update: Rebased on the latest dev version for easier merging

@jacobian91
Copy link
Author

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

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

Successfully merging this pull request may close these issues.

3 participants