func analyzeFile(filename string, resize bool) (*Cover, error) { file, err := os.Open(filename) if err != nil { return nil, err } defer file.Close() img, _, err := image.Decode(file) if err != nil { return nil, err } if resize { start := time.Now() g := gift.New(gift.Resize(500, 0, gift.LanczosResampling)) dst := image.NewRGBA(g.Bounds(img.Bounds())) g.Draw(dst, img) img = dst fmt.Printf("- RESIZE %s took %s\n", path.Base(filename), time.Since(start)) } start := time.Now() bg, c1, c2, c3 := colorart.Analyze(img) fmt.Printf("- ANALYZE %s took %s\n", path.Base(filename), time.Since(start)) return &Cover{filename, bg.String(), c1.String(), c2.String(), c3.String()}, nil }
func analyzeFile(filename string) (bg, c1, c2, c3 colorart.Color) { file, err := os.Open(filename) defer file.Close() if err != nil { log.Fatal(err) } img, _, err := image.Decode(file) if err != nil { log.Fatal(err) } b := img.Bounds() if b.Max.X-b.Min.X > resizeThreshold || b.Max.Y-b.Min.Y > resizeThreshold { g := gift.New(gift.Resize(resizeSize, 0, gift.LanczosResampling)) dst := image.NewRGBA(image.Rect(0, 0, resizeSize, resizeSize)) g.Draw(dst, img) img = dst } return colorart.Analyze(img) }