diff --git a/README.md b/README.md index a42d9fd..ba223d0 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ a simple web server serving (scaled) images and color palettes for [slideshow](h - `/`: request the name of a random image - `/image/[?resolution=1920x1080]`: request the named image (in the specified resolution) -- `/palette/`: request the color palette of the named image +- `/palette/[?colors=16&algorithm=wsm]`: request the color palette of the named image (with the specified amount of colors and algorithm) ## configuration @@ -22,8 +22,6 @@ configuration is entirely done via environment variables. | SLIDESHOW_PORT | 3000 | the port of the web server | | SLIDESHOW_DIRECTORY | "$HOME" | path to a directory containing images | | SLIDESHOW_SCANINTERVAL | 60 | the interval for directory scans in seconds | -| SLIDESHOW_PALETTE_ALGORITHM | "wsm" | the algorithm used to generate the color palette | -| SLIDESHOW_PALETTE_COLORS | 16 | the amount of colors generated | | SLIDESHOW_LOGLEVEL | "info" | the log level | **note:** diff --git a/internal/api/server.go b/internal/api/server.go index ac7f87f..404c5a1 100644 --- a/internal/api/server.go +++ b/internal/api/server.go @@ -66,5 +66,9 @@ func servePalette(writer http.ResponseWriter, request *http.Request) { response.send(writer) return } - streamColorPalette(writer, image) + amount, _ := strconv.Atoi(request.URL.Query().Get("colors")) + if amount <= 0 { + amount = 16 + } + streamColorPalette(writer, image, amount, request.URL.Query().Get("algorithm")) } diff --git a/internal/api/stream.go b/internal/api/stream.go index a2ab49e..e112fd4 100644 --- a/internal/api/stream.go +++ b/internal/api/stream.go @@ -26,11 +26,15 @@ func streamImage(writer http.ResponseWriter, image string, resolution string) { } // stream a color palette -func streamColorPalette(writer http.ResponseWriter, image string) { +func streamColorPalette(writer http.ResponseWriter, image string, amount int, algorithm string) { timestamp := time.Now().UnixMilli() var response response - amount := config.PaletteColors - colors, error := color_thief.GetPaletteFromFile(image, amount, config.PaletteAlgorithm) + algo := 1 + algorithm = strings.ToLower(algorithm) + if algorithm == "wu" { + algo = 0 + } + colors, error := color_thief.GetPaletteFromFile(image, amount, algo) if error != nil { loggo.Error("encountered an error getting the color palette from image '"+image+"'", error.Error()) response.error = error @@ -51,7 +55,7 @@ func streamColorPalette(writer http.ResponseWriter, image string) { } data := []byte(palette) writer.Write(data) - loggo.InfoTimed("successfully streamed color palette for image '"+image+"'", timestamp, "size: "+internal.FormatBytes(int64(len(data)))) + loggo.InfoTimed("successfully streamed color palette for image '"+image+"'", timestamp, "size: "+internal.FormatBytes(int64(len(data))), "colors: "+strconv.Itoa(amount), "algorithm: "+algorithm) } // stream an unscaled image diff --git a/internal/config/config.go b/internal/config/config.go index a115041..8fc1e9c 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -14,9 +14,6 @@ var ServerAddress string var ServerPort int var Directory string var ScanInterval time.Duration -var PaletteAlgorithm int -var PaletteColors int -var BufferSize int var ConvertAvailable bool // initialize the config @@ -48,22 +45,6 @@ func Initialize() { tmpInt = 60 } ScanInterval = time.Duration(tmpInt) * time.Second - tmpString := os.Getenv("SLIDESHOW_PALETTE_ALGORITHM") - if strings.ToLower(tmpString) == "wu" { - PaletteAlgorithm = 0 - } else { - PaletteAlgorithm = 1 - } - tmpInt, _ = strconv.Atoi(os.Getenv("SLIDESHOW_PALETTE_COLORS")) - if tmpInt <= 0 { - tmpInt = 16 - } - PaletteColors = tmpInt - tmpInt, _ = strconv.Atoi(os.Getenv("SLIDESHOW_BUFFERSIZE")) - if tmpInt <= 0 { - tmpInt = 4096 - } - BufferSize = tmpInt checkConvertCommand() } diff --git a/slideshow-api.service b/slideshow-api.service index e553eb9..07d9e06 100644 --- a/slideshow-api.service +++ b/slideshow-api.service @@ -9,9 +9,6 @@ Environment="SLIDESHOW_ADDRESS=0.0.0.0" Environment="SLIDESHOW_PORT=3000" Environment="SLIDESHOW_DIRECTORY=$HOME" Environment="SLIDESHOW_SCANINTERVAL=60" -Environment="SLIDESHOW_RESOLUTION=" -Environment="SLIDESHOW_PALETTE_ALGORITHM=wsm" -Environment="SLIDESHOW_PALETTE_COLORS=16" Environment="SLIDESHOW_LOGLEVEL=info" ExecStart=/opt/slideshow-api/slideshow-api