Added http and img packages
This commit is contained in:
parent
87929750ae
commit
16f900dc21
|
@ -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"))
|
||||
}
|
|
@ -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
|
||||
}
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue