Skip to content

Commit

Permalink
adds max image size
Browse files Browse the repository at this point in the history
  • Loading branch information
michiwend committed Oct 17, 2014
1 parent 40388d4 commit 27f337f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion service/placeholder.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
)

func serveImage(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "image/png")

params := mux.Vars(r)
r.ParseForm()
Expand All @@ -22,12 +21,19 @@ func serveImage(w http.ResponseWriter, r *http.Request) {
// FIXME err handling

img, _ := goplaceholder.Placeholder(
if width > 4000 || height > 4000 {
w.Header().Set("Content-Type", "text/html")
w.Write([]byte("image too large"))
return
}

text,
"/usr/share/fonts/TTF/DejaVuSans-Bold.ttf",
color.RGBA{150, 150, 150, 255},
color.RGBA{204, 204, 204, 255},
int(width), int(height))

w.Header().Set("Content-Type", "image/png")
png.Encode(w, img)
log.Printf("served image: w: %d h: %d\n", width, height)
}
Expand Down

0 comments on commit 27f337f

Please sign in to comment.