func (server *Server) buildArgumentsRotate(arguments *list.List, params imageserver.Params) error {
	rotate, _ := params.GetInt("rotate")
	if rotate != 0 {
		if rotate < 0 || rotate > 359 {
			return &imageserver.ParamError{Param: "rotate", Message: "Invalid rotate parameter"}
		}

		arguments.PushBack("-rotate")
		arguments.PushBack(strconv.Itoa(rotate))
	}
	return nil
}
Beispiel #2
0
func getDimension(name string, params imageserver.Params) (int, error) {
	if !params.Has(name) {
		return 0, nil
	}
	dimension, err := params.GetInt(name)
	if err != nil {
		return 0, err
	}
	if dimension < 0 {
		return 0, &imageserver.ParamError{Param: name, Message: "must be greater than or equal to 0"}
	}
	return dimension, nil
}
Beispiel #3
0
func getDimension(name string, max int, params imageserver.Params) (uint, error) {
	if !params.Has(name) {
		return 0, nil
	}
	d, err := params.GetInt(name)
	if err != nil {
		return 0, err
	}
	if d < 0 {
		return 0, &imageserver.ParamError{Param: name, Message: "must be greater than or equal to 0"}
	}
	if max > 0 && d > max {
		return 0, &imageserver.ParamError{Param: name, Message: fmt.Sprintf("must be less than or equal to %d", max)}
	}
	return uint(d), nil
}
Beispiel #4
0
func TestParseQueryInt(t *testing.T) {
	req, err := http.NewRequest("GET", "http://localhost?int=42", nil)
	if err != nil {
		t.Fatal(err)
	}
	params := imageserver.Params{}
	err = ParseQueryInt("int", req, params)
	if err != nil {
		t.Fatal(err)
	}
	i, err := params.GetInt("int")
	if err != nil {
		t.Fatal(err)
	}
	if i != 42 {
		t.Fatal("not equals")
	}
}
Beispiel #5
0
func (enc *Encoder) getQuality(params imageserver.Params) (int, error) {
	if !params.Has("quality") {
		if enc.DefaultQuality != 0 {
			return enc.DefaultQuality, nil
		}
		return jpeg.DefaultQuality, nil
	}
	quality, err := params.GetInt("quality")
	if err != nil {
		return 0, err
	}
	if quality < 1 {
		return 0, &imageserver.ParamError{Param: "quality", Message: "must be greater than or equal to 1"}
	}
	if quality > 100 {
		return 0, &imageserver.ParamError{Param: "quality", Message: "must be less than or equal to 100"}
	}
	return quality, nil
}
func TestQualityParserParse(t *testing.T) {
	parser := &QualityParser{}
	req, err := http.NewRequest("GET", "http://localhost?quality=50", nil)
	if err != nil {
		t.Fatal(err)
	}
	params := imageserver.Params{}
	err = parser.Parse(req, params)
	if err != nil {
		t.Fatal(err)
	}
	quality, err := params.GetInt("quality")
	if err != nil {
		t.Fatal(err)
	}
	if quality != 50 {
		t.Fatal("not equals")
	}
}
Beispiel #7
0
func (hdr *Handler) buildArgumentsQuality(arguments *list.List, params imageserver.Params, format string) error {
	if !params.Has("quality") {
		return nil
	}
	quality, err := params.GetInt("quality")
	if err != nil {
		return err
	}
	if quality < 0 {
		return &imageserver.ParamError{Param: "quality", Message: "must be greater than or equal to 0"}
	}
	if format == "jpeg" {
		if quality < 0 || quality > 100 {
			return &imageserver.ParamError{Param: "quality", Message: "must be between 0 and 100"}
		}
	}
	arguments.PushBack("-quality")
	arguments.PushBack(strconv.Itoa(quality))
	return nil
}
Beispiel #8
0
func (prc *Processor) getBounds(params imageserver.Params) (image.Rectangle, error) {
	var bds image.Rectangle
	var err error
	bds.Min.X, err = params.GetInt("min_x")
	if err != nil {
		return image.ZR, err
	}
	bds.Min.Y, err = params.GetInt("min_y")
	if err != nil {
		return image.ZR, err
	}
	bds.Max.X, err = params.GetInt("max_x")
	if err != nil {
		return image.ZR, err
	}
	bds.Max.Y, err = params.GetInt("max_y")
	if err != nil {
		return image.ZR, err
	}
	return bds, nil
}