imgcat icon indicating copy to clipboard operation
imgcat copied to clipboard

Make the library imgcat useful for people who want to embed images

Open muesli opened this issue 4 years ago • 10 comments

I think we should split this project up into a library (root folder of the repo) and the imgcat command itself (probably in /cmd/imgcat).

I'd love to use this in glow / glamour to optionally display images :heart:

muesli avatar Oct 28 '20 06:10 muesli

That would be cool!

What kind of function signature would be best for glow?

something like:

func ImageToString(img image.Image) []string

or would you like a higher level one?

func ImageToString(imgPath string, width, height uint) ([]string, error)

trashhalo avatar Oct 28 '20 13:10 trashhalo

Great minds think alike I guess. I did pretty much this in #12, mostly following the same pattern that https://github.com/charmbracelet/bubbles seemed to follow for the components. As in just directly exposing the Model structure.

schoentoon avatar Oct 28 '20 15:10 schoentoon

if we are going to make a model/component. I wonder if the most usable form is just { width, height, url/filepath }, then you can embed any number of images anywhere without the assumption of a full screen q to quit setup.

trashhalo avatar Oct 28 '20 16:10 trashhalo

For now I just used the model as is. Meaning all properties are private. Making width, height and urls public is probably a good idea. I would like to add that an offline toggle (so not accepting http urls) is probably a good idea for providing this as a library, but I'd say that would deserve it's own issue/pull request later on.

schoentoon avatar Oct 28 '20 16:10 schoentoon

Having ImageToString is convenient and nice, but I think I'd prefer passing either an image.Image or an io.Reader to it. That makes it a lot more flexible in regards to where the image is stored.

muesli avatar Oct 28 '20 16:10 muesli

I was actually already planning on following up with another pull request later on adding support for image.Image and/or io.Reader later down the line. I suppose I will look into implementing this later today.

schoentoon avatar Oct 28 '20 16:10 schoentoon

Awesome, can't wait for that @schoentoon!

muesli avatar Oct 28 '20 16:10 muesli

This will be our tracking ticket for how we want the library to look when we finish shaking out the assumptions of the original impl. So not closing even though we did a first pass.

trashhalo avatar Oct 28 '20 18:10 trashhalo

I will most likely add a few methods like AddImage(image image.Image) and AddImageFromReader(reader io.Reader) to the Model structure we have now. Along with changing NewModel() to something like NewModel(image image.Image) and NewModelFromReader(reader io.Reader). Getting rid of the current urls part completely, leaving the opening of files or images over http on the caller. Although we could decide to add helpers for file and http alongside it.

schoentoon avatar Oct 28 '20 18:10 schoentoon

Any news on this? I was interested in trying out Bubbletea, but it seems your program is the closest thing you can get for displaying images, so having it as a bubble component would be great.

erazemk avatar Apr 05 '22 10:04 erazemk