Add support for JPEG images

This commit is contained in:
Paul-Christian Volkmer 2024-05-25 23:23:16 +02:00
parent 037f63466a
commit 0757e484f6
2 changed files with 5 additions and 0 deletions

View File

@ -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))

View File

@ -189,6 +189,7 @@
<label for="contenttype">Content-Type</label>
<select id="contenttype" onchange="newcontenttype(this.value)">
<option value="png" selected>PNG</option>
<option value="jpeg">JPEG</option>
<option value="svg">SVG</option>
</select>
</div>