本文整理匯總了Golang中github.com/pierrre/imageserver.Params類的典型用法代碼示例。如果您正苦於以下問題:Golang Params類的具體用法?Golang Params怎麽用?Golang Params使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Params類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: getResampling
func (prc *ResizeProcessor) getResampling(params imageserver.Params) (gift.Resampling, error) {
if !params.Has("resampling") {
if prc.DefaultResampling != nil {
return prc.DefaultResampling, nil
}
return gift.NearestNeighborResampling, nil
}
rsp, err := params.GetString("resampling")
if err != nil {
return nil, err
}
switch rsp {
case "nearest_neighbor":
return gift.NearestNeighborResampling, nil
case "box":
return gift.BoxResampling, nil
case "linear":
return gift.LinearResampling, nil
case "cubic":
return gift.CubicResampling, nil
case "lanczos":
return gift.LanczosResampling, nil
}
return nil, &imageserver.ParamError{Param: "resampling", Message: "invalid value"}
}
示例2: buildArgumentsMonochrome
func (server *Server) buildArgumentsMonochrome(arguments *list.List, params imageserver.Params) error {
monochrome, _ := params.GetBool("monochrome")
if monochrome {
arguments.PushBack("-monochrome")
}
return nil
}
示例3: buildArgumentsCrop
func (server *Server) buildArgumentsCrop(arguments *list.List, params imageserver.Params) error {
if !params.Has("crop") {
return nil
}
crop, _ := params.GetString("crop")
cropArgs := strings.Split(crop, ",")
cropArgsLen := len(cropArgs)
if cropArgsLen != 2 && cropArgsLen != 4 {
return &imageserver.ParamError{Param: "crop", Message: "Invalid crop request, parameters number mismatch"}
}
if cropArgsLen == 2 {
width, _ := strconv.Atoi(cropArgs[0])
height, _ := strconv.Atoi(cropArgs[1])
arguments.PushBack("-crop")
arguments.PushBack(fmt.Sprintf("%dx%d", width, height))
arguments.PushBack("+repage")
}
if cropArgsLen == 4 {
width, _ := strconv.Atoi(cropArgs[0])
height, _ := strconv.Atoi(cropArgs[1])
x, _ := strconv.Atoi(cropArgs[2])
y, _ := strconv.Atoi(cropArgs[3])
arguments.PushBack("-crop")
arguments.PushBack(fmt.Sprintf("%dx%d+%d+%d", width, height, x, y))
arguments.PushBack("+repage")
}
return nil
}
示例4: buildArgumentsFlop
func (server *Server) buildArgumentsFlop(arguments *list.List, params imageserver.Params) error {
flop, _ := params.GetBool("flop")
if flop {
arguments.PushBack("-flop")
}
return nil
}
示例5: process
func process(nim image.Image, params imageserver.Params) (image.Image, error) {
if params.Empty() {
return nim, nil
}
width, err := getDimension("width", params)
if err != nil {
return nil, err
}
height, err := getDimension("height", params)
if err != nil {
return nil, err
}
if width == 0 && height == 0 {
return nim, nil
}
interp, err := getInterpolation(params)
if err != nil {
return nil, err
}
mode, err := getModeFunc(params)
if err != nil {
return nil, err
}
nim = mode(width, height, nim, interp)
return nim, nil
}
示例6: getInterpolation
func (prc *Processor) getInterpolation(params imageserver.Params) (resize.InterpolationFunction, error) {
if !params.Has("interpolation") {
return prc.DefaultInterpolation, nil
}
interpolation, err := params.GetString("interpolation")
if err != nil {
return 0, err
}
switch interpolation {
case "nearest_neighbor":
return resize.NearestNeighbor, nil
case "bilinear":
return resize.Bilinear, nil
case "bicubic":
return resize.Bicubic, nil
case "mitchell_netravali":
return resize.MitchellNetravali, nil
case "lanczos2":
return resize.Lanczos2, nil
case "lanczos3":
return resize.Lanczos3, nil
default:
return 0, &imageserver.ParamError{Param: "interpolation", Message: "invalid value"}
}
}
示例7: buildArgumentsGravity
func (server *Server) buildArgumentsGravity(arguments *list.List, params imageserver.Params) error {
gravity, _ := params.GetString("gravity")
var translatedGravity string
if gravity != "" {
switch {
case gravity == "n":
translatedGravity = "North"
case gravity == "s":
translatedGravity = "South"
case gravity == "e":
translatedGravity = "East"
case gravity == "w":
translatedGravity = "West"
case gravity == "ne":
translatedGravity = "NorthEast"
case gravity == "se":
translatedGravity = "SouthEast"
case gravity == "nw":
translatedGravity = "NorthWest"
case gravity == "sw":
translatedGravity = "SouthWest"
}
if translatedGravity == "" {
return &imageserver.ParamError{Param: "gravity", Message: "gravity should n, s, e, w, ne, se, nw or sw"}
}
} else {
// Default gravity is center.
translatedGravity = "Center"
}
arguments.PushBack("-gravity")
arguments.PushBack(fmt.Sprintf("%s", translatedGravity))
return nil
}
示例8: buildArgumentsGrey
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
}
示例9: buildArgumentsInterlace
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
}
示例10: buildArgumentsTrim
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
}
示例11: Get
// Get implements imageserver.Server.
func (s *Server) Get(params imageserver.Params) (*imageserver.Image, error) {
src, err := params.Get(Param)
if err != nil {
return nil, err
}
params = imageserver.Params{Param: src}
return s.Server.Get(params)
}
示例12: getPath
func (srv *Server) getPath(params imageserver.Params) (string, error) {
src, err := params.GetString(imageserver_source.Param)
if err != nil {
return "", err
}
// This trick comes from net/http.Dir.Open().
// It allows to "jail" the path inside the root.
return filepath.Join(srv.Root, filepath.FromSlash(path.Clean("/"+src))), nil
}
示例13: TestParseQueryStringUndefined
func TestParseQueryStringUndefined(t *testing.T) {
req, err := http.NewRequest("GET", "http://localhost", nil)
if err != nil {
t.Fatal(err)
}
params := imageserver.Params{}
ParseQueryString("string", req, params)
if params.Has("string") {
t.Fatal("should not be set")
}
}
示例14: ParseQueryFloat
// ParseQueryFloat takes the param from the query string, parse it as a float64 and add it to params.
func ParseQueryFloat(param string, req *http.Request, params imageserver.Params) error {
s := req.URL.Query().Get(param)
if s == "" {
return nil
}
f, err := strconv.ParseFloat(s, 64)
if err != nil {
return newParseTypeParamError(param, "float", err)
}
params.Set(param, f)
return nil
}
示例15: buildArgumentsRotate
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
}