func generateMosaic(tag string, in image.Image, m *mosaicRecord) { // First build a color palette. log.Printf("Mosaic[%s] Create Palette...", m.ID) p := mosaic.NewImagePalette(paletteSize) if err := thumbs.PopulatePalette(tag, p); err != nil { log.Printf("Failed to populate palette: %s", err) if err := mosaics.SetStatus(m.ID, MosaicStatusFailed); err != nil { log.Printf("Failed to set mosaic failed: %s", err) } return } log.Printf("Mosaic[%s] Create Palette Done with %d colors, %d images.", m.ID, p.NumColors(), p.NumImages()) // Update that the mosaic is being worked on. if err := mosaics.SetStatus(m.ID, MosaicStatusWorking); err != nil { log.Printf("Failed to set working status: %s", err) return } // Generate the mosaic. log.Printf("Mosaic[%s] Compose...", m.ID) out := mosaic.ComposeSquare(in, Units, UnitSize, p) log.Printf("Mosaic[%s] Compose Done.", m.ID) // Store the image and update the the mosaic is done. if err := mosaics.StoreImage(m.ID, out); err != nil { log.Printf("Failed to store mosaic image: %s", err) return } if err := mosaics.SetStatus(m.ID, MosaicStatusCreated); err != nil { log.Printf("Failed to set mosaic created: %s", err) return } }
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 }