From 0757e484f66869561502b7dc0817faadcd0d6601 Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Sat, 25 May 2024 23:23:16 +0200 Subject: [PATCH] Add support for JPEG images --- idicon.go | 4 ++++ static/index.html | 1 + 2 files changed, 5 insertions(+) diff --git a/idicon.go b/idicon.go index 568d3a6..5f4f966 100644 --- a/idicon.go +++ b/idicon.go @@ -7,6 +7,7 @@ import ( "github.com/BurntSushi/toml" "github.com/gorilla/mux" "idicon/icons" + "image/jpeg" "image/png" "log" "net/http" @@ -81,6 +82,9 @@ func requestHandler(w http.ResponseWriter, r *http.Request) { if ct == "svg" || cth == "image/svg+xml" { w.Header().Add("Content-Type", "image/svg+xml") _, err = w.Write([]byte(iconGenerator.GenSvg(id, size))) + } else if ct == "jpeg" || cth == "image/jpeg" { + w.Header().Add("Content-Type", "image/webp") + err = jpeg.Encode(w, iconGenerator.GenIcon(id, size), nil) } else { w.Header().Add("Content-Type", "image/png") err = png.Encode(w, iconGenerator.GenIcon(id, size)) diff --git a/static/index.html b/static/index.html index 7e18aa8..4ef8d90 100644 --- a/static/index.html +++ b/static/index.html @@ -189,6 +189,7 @@