Display image values using Sixel terminal protocol
Requesting here as https://github.com/jqlang/jq/discussions/3291 maybe also great addition to this project:
Sixel allows to display images in terminals ( e.g. https://github.com/saitoha/libsixel ; https://en.wikipedia.org/wiki/Sixel ; https://github.com/atanunq/viu (Rust) ), let's make --sixel flag that will :
- under each value (in pretty print mode) that contains image (e.g. base64 encoded) to display "key-name:" and after that display image using sixel
- that would require detecting if given value is base64 and later if is some supported image file (e.g. png, jpg, webp, etc) (e.g. --img auto flag)
- alternatively pointing manually at keys to try to decode as image ( --img .data.key.img )
Rationale:
- more and more APIs return image encoded as value, or AI/ML datasets, contain images in json files as values.
If you decide to add support you can always reply to https://x.com/GWierzowiecki/status/1898510522221461577 :) Thank you!
Btw. I gave a try in
- https://github.com/VariousForks/jaq/tree/issue-267-sixel-images branch (
jaq --img auto < with_images.json)
with this test payload json with base64 png image as one of values:
- Example JSON with PNG base64 value: https://gist.github.com/gwpl/f770639a0a21025ec5c1c775a200ddc8
Currently it "almost works" , in my terminal it just jumps to 0x0 cortner then displaying image, instead of behaving like viu ( https://github.com/atanunq/viu - that uses viuer btw.) or lsix, which display image in next line, and continue with printing text after image...
Hi @gwpl, thanks a lot for the idea and your work on the sixel branch! Funnily, just today, before seeing your post, I thought about precisely the same functionality (showing image data directly from jaq), so I'm definitely interested. I think that to be flexible, I would not add a command-line flag, but a filter that interprets an image as image, e.g. .img |= (@base64d | @pngd). I can adapt your work to this, once you figure out how to make the image appear at the right position.
Lovely!
Please, I don't know when I will have spare moment to sit and debug this,
if I will I will do, otherwise as you see I made ticket on repo of library asking for help, so hopefully it will work out...
... otherwise, please try viu command line tool yourself that is CLI wrapper around library I used, and maybe that will give you a feel how to make it work.
Also I don't mind if anyone will make new branch and drop mine, I just would love to see that feature , and hopefully my work will be good starting point or inspiration to others.
Otherwise, if spare moment comes, will try to push debugging deeper.
(or if someone finds issue please write in this issue I am happy to apply changes, advice to my branch and update it)
@gwpl, do not worry and take your time, if you want to continue your effort on this feature. I'm not in a hurry. :)
I've found fix!
Works! Pull Reuqest: https://github.com/01mf02/jaq/pull/269
Wow, thanks for your work, this looks already quite good! I have left a few comments in your PR to help you improve your code.
More updates on https://github.com/01mf02/jaq/pull/269 !
2025-03-14--jaq-issue-267-with-identation.json
(updating gist with used jsons with images: https://gist.github.com/gwpl/f770639a0a21025ec5c1c775a200ddc8 )
Hello, can I help with review? IIUC Convention is to respond to reviewer comments, and reviewer to close discussions, however if you wish otherwise, I am glad to help and follow.
@gwpl, see my comment in #269.