示例#1
0
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
}
示例#2
0
// Change implements Processor.
func (proc *Processor) Change(params imageserver.Params) bool {
	if !params.Has(Param) {
		return false
	}
	params, err := params.GetParams(Param)
	if err != nil {
		return true
	}
	if params.Empty() {
		return false
	}
	if params.Has("width") {
		return true
	}
	if params.Has("height") {
		return true
	}
	if params.Has("interpolation") {
		return true
	}
	if params.Has("mode") {
		return true
	}
	return false
}
示例#3
0
// Parse implements Parser.
func (parser *Parser) Parse(req *http.Request, params imageserver.Params) error {
	p := imageserver.Params{}
	err := parse(req, p)
	if err != nil {
		if err, ok := err.(*imageserver.ParamError); ok {
			err.Param = Param + "." + err.Param
		}
		return err
	}
	if !p.Empty() {
		params.Set(Param, p)
	}
	return nil
}
示例#4
0
func (srv *ValidateParamsServer) validate(params imageserver.Params) error {
	if params.Empty() {
		return nil
	}
	err := validateDimension("width", srv.WidthMax, params)
	if err != nil {
		return err
	}
	err = validateDimension("height", srv.HeightMax, params)
	if err != nil {
		return err
	}
	return nil
}
示例#5
0
// Change implements imageserver/image.Processor.
func (prc *RotateProcessor) Change(params imageserver.Params) bool {
	if !params.Has(rotateParam) {
		return false
	}
	params, err := params.GetParams(rotateParam)
	if err != nil {
		return true
	}
	if params.Empty() {
		return false
	}
	if params.Has("rotation") {
		return true
	}
	return false
}
示例#6
0
// Change implements imageserver/image.Processor.
func (prc *ResizeProcessor) Change(params imageserver.Params) bool {
	if !params.Has(resizeParam) {
		return false
	}
	params, err := params.GetParams(resizeParam)
	if err != nil {
		return true
	}
	if params.Empty() {
		return false
	}
	if params.Has("width") {
		return true
	}
	if params.Has("height") {
		return true
	}
	return false
}
示例#7
0
// Handle implements imageserver.Handler.
func (hdr *Handler) Handle(im *imageserver.Image, params imageserver.Params) (*imageserver.Image, error) {
	if !params.Has(param) {
		return im, nil
	}
	params, err := params.GetParams(param)
	if err != nil {
		return nil, err
	}
	if params.Empty() {
		return im, nil
	}
	im, err = hdr.handle(im, params)
	if err != nil {
		if err, ok := err.(*imageserver.ParamError); ok {
			err.Param = param + "." + err.Param
		}
		return nil, err
	}
	return im, nil
}
示例#8
0
// Process implements Processor.
func (prc *Processor) Process(nim image.Image, params imageserver.Params) (image.Image, error) {
	if !params.Has(Param) {
		return nim, nil
	}
	params, err := params.GetParams(Param)
	if err != nil {
		return nil, err
	}
	if params.Empty() {
		return nim, nil
	}
	nim, err = prc.process(nim, params)
	if err != nil {
		if err, ok := err.(*imageserver.ParamError); ok {
			err.Param = fmt.Sprintf("%s.%s", Param, err.Param)
		}
		return nil, err
	}
	return nim, nil
}
// Get implements Server.
func (server *Server) Get(params imageserver.Params) (*imageserver.Image, error) {
	im, err := server.Server.Get(params)
	if err != nil {
		return nil, err
	}
	if !params.Has(globalParam) {
		return im, nil
	}
	params, err = params.GetParams(globalParam)
	if err != nil {
		return nil, err
	}
	if params.Empty() {
		return im, nil
	}
	im, err = server.process(im, params)
	if err != nil {
		if err, ok := err.(*imageserver.ParamError); ok {
			err.Param = globalParam + "." + err.Param
		}
		return nil, err
	}
	return im, nil
}