Beispiel #1
0
func downloadImages(tag string, numImages int, inv *mosaic.ImageInventory) error {
	api := instagram.NewClient()
	fetcher := instagram.NewTagFetcher(api, tag)
	if err := inv.Fetch(fetcher, numImages); err != nil {
		return err
	}
	time.Sleep(1 * time.Second)
	return nil
}
Beispiel #2
0
func generateMosaic(src image.Image, tag string, units int, solid bool, inv *mosaic.ImageInventory) (image.Image, error) {
	var p *mosaic.ImagePalette
	if solid {
		p = mosaic.NewSolidPalette(palette.WebSafe)
		log.Printf("Generating %dx%d solid mosaic with %d colors", units, units, p.NumColors())
	} else {
		p = mosaic.NewImagePalette(paletteSize)
		if err := inv.PopulatePalette(p); err != nil {
			return nil, err
		}
		if p.NumColors() == 0 {
			return nil, fmt.Errorf("No images are available")
		}
		log.Printf("Generating %dx%d %s mosaic with %d colors and %d images\n", units, units, tag, p.NumColors(), p.NumImages())
	}
	sq := mosaic.ComposeSquare(src, units, unitSize, p)
	return mosaic.Shrink(sq, outDownsample), nil
}