From 16f900dc213090be1775a623ed5b6a820ddf62e9 Mon Sep 17 00:00:00 2001 From: B Newman Date: Sun, 10 Nov 2024 11:57:46 -0500 Subject: [PATCH] Added http and img packages --- http/http.go | 11 ++++++++++ img/img.go | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ mega/mega.go | 3 ++- 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 http/http.go create mode 100644 img/img.go diff --git a/http/http.go b/http/http.go new file mode 100644 index 0000000..f5f7998 --- /dev/null +++ b/http/http.go @@ -0,0 +1,11 @@ +package http + +import ( + "net/http" + "strings" +) + +func IsMobile(r *http.Request) bool { + return (strings.Contains(strings.ToLower(r.Header.Get("User-Agent")), "android") || + strings.Contains(strings.ToLower(r.Header.Get("User-Agent")), "iphone")) +} diff --git a/img/img.go b/img/img.go new file mode 100644 index 0000000..1aab4e9 --- /dev/null +++ b/img/img.go @@ -0,0 +1,59 @@ +package img + +import ( + "image" + "image/draw" + "image/png" + "os" + + "github.com/anthonynsimon/bild/adjust" +) + +const ( + StyleDark = 0.70 +) + +func Overlay(inputFile, overlayFile string, style float64) (err error) { + thumb, err := os.Open(inputFile) + if err != nil { + return err + } + + overlay, err := os.Open(overlayFile) + if err != nil { + return err + } + + img0, err := png.Decode(thumb) + if err != nil { + return err + } + defer thumb.Close() + + img1, err := png.Decode(overlay) + if err != nil { + return err + } + defer overlay.Close() + + b0 := img0.Bounds() + b1 := img1.Bounds() + + img0 = adjust.Brightness(img0, style) + + offset := image.Pt(b0.Dx()/2-b1.Dx()/2, b0.Dy()/2-b1.Dy()/2) + + m := image.NewRGBA(b0) + draw.Draw(m, b0, img0, image.Point{}, draw.Src) + draw.Draw(m, img1.Bounds().Add(offset), img1, image.Point{}, draw.Over) + + imgw, err := os.Create(inputFile) + if err != nil { + return err + } + + png.Encode(imgw, m) + defer imgw.Close() + + return nil +} diff --git a/mega/mega.go b/mega/mega.go index a2f7750..d205822 100644 --- a/mega/mega.go +++ b/mega/mega.go @@ -93,7 +93,8 @@ func Find(dir, pattern, sortorder string) (files []FileInfo, err error) { lines := strings.Split(string(out), "\n") for _, line := range lines { - files = append(files, FileInfo{filepath.Dir(line), filepath.Base(line), filepath.Join(dir, line)}) + files = append(files, FileInfo{filepath.Dir(line), filepath.Base(line), line}) + //files = append(files, FileInfo{filepath.Dir(line), filepath.Base(line), filepath.Join(dir, line)}) } if len(sortorder) == 0 {