From ae69fef0e6def1034b547771e85f2426cdc5e3eb Mon Sep 17 00:00:00 2001 From: Anne Douwe Bouma Date: Sun, 25 Oct 2020 17:45:44 +0100 Subject: [PATCH 1/3] docs: Add prebuilt packages to README.md --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3d12021..4de29c6 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,10 @@ Tool to output images in the terminal. Built with [bubbletea](https://github.com brew install trashhalo/homebrew-brews/imgcat ``` +### prebuilt packages + +Prebuilt packages can be found at the [releases page](https://github.com/trashhalo/imgcat/releases) + ### golang ``` @@ -30,4 +34,4 @@ imgcat *.jpg ``` - j, down: next image -- k, up: previous image \ No newline at end of file +- k, up: previous image From 933616c38b7d63b28680053d1e3dd4084b5591d8 Mon Sep 17 00:00:00 2001 From: orhun Date: Sun, 25 Oct 2020 20:18:57 +0300 Subject: [PATCH 2/3] add aur instructions --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 3d12021..271ce19 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,12 @@ brew install trashhalo/homebrew-brews/imgcat go get github.com/trashhalo/imgcat ``` +### aur + +``` +yay -S imgcat +``` + ## sample output ``` imgcat https://i.redd.it/65fmdbh1ja951.jpg From 6d01cbf8cd498676d91c5cfbbe9fe1c23fff4f0b Mon Sep 17 00:00:00 2001 From: kubuzetto Date: Mon, 26 Oct 2020 13:59:57 -0700 Subject: [PATCH 3/3] Horizontally fit or center images --- main.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index ab59548..dfc678f 100644 --- a/main.go +++ b/main.go @@ -49,6 +49,7 @@ type model struct { selected int urls []string image string + width uint height uint err error } @@ -66,6 +67,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg := msg.(type) { case tea.WindowSizeMsg: + m.width = uint(msg.Width) m.height = uint(msg.Height) return m, load(m.urls[m.selected]) case tea.KeyMsg: @@ -94,7 +96,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { url := m.urls[m.selected] if msg.resp != nil { defer msg.resp.Body.Close() - img, err := readerToImage(m.height, url, msg.resp.Body) + img, err := readerToImage(m.width, m.height, url, msg.resp.Body) if err != nil { return m, func() tea.Msg { return errMsg{err} } } @@ -102,7 +104,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, nil } defer msg.file.Close() - img, err := readerToImage(m.height, url, msg.file) + img, err := readerToImage(m.width, m.height, url, msg.file) if err != nil { return m, func() tea.Msg { return errMsg{err} } } @@ -148,19 +150,22 @@ func load(url string) tea.Cmd { } } -func readerToImage(height uint, url string, r io.Reader) (string, error) { +func readerToImage(width uint, height uint, url string, r io.Reader) (string, error) { img, _, err := image.Decode(r) if err != nil { return "", err } - img = resize.Resize(0, height*2, img, resize.Lanczos3) + img = resize.Thumbnail(width, height*2, img, resize.Lanczos3) b := img.Bounds() w := b.Max.X h := b.Max.Y p := termenv.ColorProfile() str := strings.Builder{} for y := 0; y < h; y += 2 { + for x := w; x < int(width); x = x + 2 { + str.WriteString(" ") + } for x := 0; x < w; x++ { c1, _ := colorful.MakeColor(img.At(x, y)) color1 := p.Color(c1.Hex())