Commit 0eaa48c7 authored by santiaago's avatar santiaago
Browse files

add xs parameter to banner routes #36

parent ec8d4081
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ import (
func BannerRandom(w http.ResponseWriter, r *http.Request) {
	width := extract.Width(r)
	height := extract.Height(r)
	xsquares := extract.XSquares(r)

	numColors := extract.NumColors(r)

@@ -38,12 +39,12 @@ func BannerRandom(w http.ResponseWriter, r *http.Request) {

	if f := extract.Format(r); f == format.JPEG {
		m := image.NewRGBA(image.Rect(0, 0, width, height))
		squares.RandomGrid(m, colors, 50)
		squares.RandomGrid(m, colors, xsquares)
		var img image.Image = m
		write.ImageJPEG(w, &img)
	} else if f == format.SVG {
		write.ImageSVG(w)
		squares.RandomGridSVG(w, colors, width, height, 50)
		squares.RandomGridSVG(w, colors, width, height, xsquares)
	}
}

@@ -52,6 +53,7 @@ func BannerRandom(w http.ResponseWriter, r *http.Request) {
func BannerRandomGradient(w http.ResponseWriter, r *http.Request) {
	width := extract.Width(r)
	height := extract.Height(r)
	xsquares := extract.XSquares(r)

	numColors := extract.NumColors(r)

@@ -73,11 +75,11 @@ func BannerRandomGradient(w http.ResponseWriter, r *http.Request) {

	if f := extract.Format(r); f == format.JPEG {
		m := image.NewRGBA(image.Rect(0, 0, width, height))
		squares.RandomGradientGrid(m, colors, 50)
		squares.RandomGradientGrid(m, colors, xsquares)
		var img image.Image = m
		write.ImageJPEG(w, &img)
	} else if f == format.SVG {
		write.ImageSVG(w)
		squares.RandomGradientGridSVG(w, colors, width, height, 50)
		squares.RandomGradientGridSVG(w, colors, width, height, xsquares)
	}
}
+14 −0
Original line number Diff line number Diff line
@@ -171,5 +171,19 @@ func Height(r *http.Request) int {
		}
	}
	return 300
}

// XSquares returns the value of the 'xs' parameter in the http.Request.
// Used to defined the number of squares that are wanted in the x axis of an image
func XSquares(r *http.Request) int {
	strXS := r.FormValue("xs")
	if len(strXS) > 0 {
		if xs, errXS := strconv.ParseInt(strXS, 0, 64); errXS == nil {
			ixs := int(xs)
			if ixs > 0 {
				return ixs
			}
		}
	}
	return 50
}