func (server *Server) buildArgumentsMonochrome(arguments *list.List, params imageserver.Params) error {
	monochrome, _ := params.GetBool("monochrome")
	if monochrome {
		arguments.PushBack("-monochrome")
	}
	return nil
}
func (server *Server) buildArgumentsFlop(arguments *list.List, params imageserver.Params) error {
	flop, _ := params.GetBool("flop")
	if flop {
		arguments.PushBack("-flop")
	}
	return nil
}
func (server *Server) buildArgumentsInterlace(arguments *list.List, params imageserver.Params) error {
	interlace, _ := params.GetBool("no_interlace")
	if !interlace {
		arguments.PushBack("-interlace")
		arguments.PushBack("Line")
	}
	return nil
}
func (server *Server) buildArgumentsTrim(arguments *list.List, params imageserver.Params) error {
	trim, _ := params.GetBool("trim")
	if trim {
		// We must execute trim first. (order of operations)
		arguments.PushFront("-trim")
	}
	return nil
}
func (server *Server) buildArgumentsGrey(arguments *list.List, params imageserver.Params) error {
	grey, _ := params.GetBool("grey")
	if grey {
		arguments.PushBack("-colorspace")
		arguments.PushBack("GRAY")
	}
	return nil
}
func (server *Server) buildArgumentsExtent(arguments *list.List, params imageserver.Params, width int, height int) error {
	if width == 0 || height == 0 {
		return nil
	}
	if !params.Has("extent") {
		return nil
	}
	extent, err := params.GetBool("extent")
	if err != nil {
		return err
	}
	if extent {
		arguments.PushBack("-extent")
		arguments.PushBack(fmt.Sprintf("%dx%d", width, height))
	}
	return nil
}
Example #7
0
func TestParseQueryBool(t *testing.T) {
	req, err := http.NewRequest("GET", "http://localhost?bool=true", nil)
	if err != nil {
		t.Fatal(err)
	}
	params := imageserver.Params{}
	err = ParseQueryBool("bool", req, params)
	if err != nil {
		t.Fatal(err)
	}
	b, err := params.GetBool("bool")
	if err != nil {
		t.Fatal(err)
	}
	if b != true {
		t.Fatal("not equals")
	}
}
Example #8
0
func TestCorrectionParserParse(t *testing.T) {
	parser := &CorrectionParser{}
	req, err := http.NewRequest("GET", "http://localhost?gamma_correction=true", nil)
	if err != nil {
		t.Fatal(err)
	}
	params := imageserver.Params{}
	err = parser.Parse(req, params)
	if err != nil {
		t.Fatal(err)
	}
	res, err := params.GetBool("gamma_correction")
	if err != nil {
		t.Fatal(err)
	}
	if res != true {
		t.Fatalf("unexpected result: got %t, want %t", res, true)
	}
}
Example #9
0
func (prc *CorrectionProcessor) isEnabled(params imageserver.Params) (bool, error) {
	if params.Has("gamma_correction") {
		return params.GetBool("gamma_correction")
	}
	return prc.enabled, nil
}
Example #10
0
func (hdr *Handler) buildArgumentsResize(arguments *list.List, params imageserver.Params) (width int, height int, err error) {
	width, err = getDimension("width", params)
	if err != nil {
		return 0, 0, err
	}
	height, err = getDimension("height", params)
	if err != nil {
		return 0, 0, err
	}
	if width == 0 && height == 0 {
		return 0, 0, nil
	}
	widthString := ""
	if width != 0 {
		widthString = strconv.Itoa(width)
	}
	heightString := ""
	if height != 0 {
		heightString = strconv.Itoa(height)
	}
	resize := fmt.Sprintf("%sx%s", widthString, heightString)
	if params.Has("fill") {
		fill, err := params.GetBool("fill")
		if err != nil {
			return 0, 0, err
		}
		if fill {
			resize = resize + "^"
		}
	}
	if params.Has("ignore_ratio") {
		ignoreRatio, err := params.GetBool("ignore_ratio")
		if err != nil {
			return 0, 0, err
		}
		if ignoreRatio {
			resize = resize + "!"
		}
	}
	if params.Has("only_shrink_larger") {
		onlyShrinkLarger, err := params.GetBool("only_shrink_larger")
		if err != nil {
			return 0, 0, err
		}
		if onlyShrinkLarger {
			resize = resize + ">"
		}
	}
	if params.Has("only_enlarge_smaller") {
		onlyEnlargeSmaller, err := params.GetBool("only_enlarge_smaller")
		if err != nil {
			return 0, 0, err
		}
		if onlyEnlargeSmaller {
			resize = resize + "<"
		}
	}
	arguments.PushBack("-resize")
	arguments.PushBack(resize)
	return width, height, nil
}