maaslalani / draw

Draw in your terminal
MIT License
460 stars 18 forks source link

Export images #5

Open leaanthony opened 2 years ago

leaanthony commented 2 years ago

Is your feature request related to a problem? Please describe. It would be great to export to an image and keep the colours in the drawing.

Describe the solution you'd like It should work like the current export but save an image instead. This library could do most of the work: https://github.com/pavelpatrin/go-ansi-to-image

Describe alternatives you've considered None

Additional context N/A

kendfss commented 2 years ago

Here's an implementation. It uses two additional environment variables DRAW_NAME and DRAW_EXT which default to /tmp/draw and .txt, respectively, but uses the appropriate procedure if it is set to .png, and will echo to stderr (before rendering a text file with the given name) if the envar/argument is not set/recognized and will fallback to DRAW_FILE if neither of the other variables are set.

So far so good, but the output images seem to be a little darker than I'd expected from the rendition my terminal (iTerm2 with few, if any, visual modifications).
Having tested it out though, I feel like it would be worth enabling this tool to export random ansi compositions to png, or having a subcommand for it.
As well as having the ability to open ansi files and continue where you leave off.

Now, while implementing this I had the following consideration. We could keep it like this, or we could only invoke the DRAW_NAME variable if DRAW_EXT is set, and then use the latter to coerce the filename to a suitable extension

With that said, one pitfall of that library, in its current form, is that its configuration is not json/yaml/etc. ready which is, at best, constraining for end users. This could be addressed by environment variables, but that's asking for a pretty hideous configuration, imo. I think there's also something to be said of it not exporting to RGBA, but that's a little less here or there.

leaanthony commented 2 years ago

Really great work! I wonder how easy it would be to get a PNG. Might have a go tonight

kendfss commented 2 years ago

Cheers! It's easy to do png because that's the only option exported by the package. As it stands you'd have to decode the png again to render to other formats.