vertical flags
This commit is contained in:
parent
46238c0ec4
commit
b00eccf427
47
bloat.go
47
bloat.go
|
@ -31,11 +31,19 @@ func bloat_showflag(writer http.ResponseWriter, req *http.Request) {
|
|||
code := mux.Vars(req)["code"]
|
||||
colors := strings.Split(code, ",")
|
||||
numcolors := len(colors)
|
||||
h := (128 / numcolors) * numcolors
|
||||
w := h * 3 / 2
|
||||
img := image.NewRGBA(image.Rect(0, 0, w, h))
|
||||
for i := 0; i < h; i++ {
|
||||
hex := colors[i*numcolors/h]
|
||||
vert := false
|
||||
if colors[0] == "vert" {
|
||||
vert = true
|
||||
colors = colors[1:]
|
||||
numcolors--
|
||||
if numcolors == 0 {
|
||||
http.Error(writer, "bad flag", 400)
|
||||
return
|
||||
}
|
||||
}
|
||||
pixels := make([][4]byte, numcolors)
|
||||
for i := 0; i < numcolors; i++ {
|
||||
hex := colors[i]
|
||||
if len(hex) == 3 {
|
||||
hex = fmt.Sprintf("%c%c%c%c%c%c",
|
||||
hex[0], hex[0], hex[1], hex[1], hex[2], hex[2])
|
||||
|
@ -44,14 +52,33 @@ func bloat_showflag(writer http.ResponseWriter, req *http.Request) {
|
|||
r := byte(c >> 16 & 0xff)
|
||||
g := byte(c >> 8 & 0xff)
|
||||
b := byte(c >> 0 & 0xff)
|
||||
pixels[i][0] = r
|
||||
pixels[i][1] = g
|
||||
pixels[i][2] = b
|
||||
pixels[i][3] = 255
|
||||
}
|
||||
|
||||
h := 128
|
||||
w := h * 3 / 2
|
||||
img := image.NewRGBA(image.Rect(0, 0, w, h))
|
||||
if vert {
|
||||
for j := 0; j < w; j++ {
|
||||
p := i*img.Stride + j*4
|
||||
img.Pix[p+0] = r
|
||||
img.Pix[p+1] = g
|
||||
img.Pix[p+2] = b
|
||||
img.Pix[p+3] = 255
|
||||
pix := pixels[j*numcolors/w][:]
|
||||
for i := 0; i < h; i++ {
|
||||
p := i*img.Stride + j*4
|
||||
copy(img.Pix[p:], pix)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for i := 0; i < h; i++ {
|
||||
pix := pixels[i*numcolors/h][:]
|
||||
for j := 0; j < w; j++ {
|
||||
p := i*img.Stride + j*4
|
||||
copy(img.Pix[p:], pix)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
writer.Header().Set("Cache-Control", "max-age="+somedays())
|
||||
png.Encode(writer, img)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue