Example #1
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
}
Example #2
0
// Get implements Server.
func (srv *ValidateParamsServer) Get(params imageserver.Params) (*imageserver.Image, error) {
	if params.Has(Param) {
		params, err := params.GetParams(Param)
		if err != nil {
			return nil, err
		}
		err = srv.validate(params)
		if err != nil {
			return nil, wrapParamError(err)
		}
	}
	return srv.Server.Get(params)
}
Example #3
0
// Process implements Processor.
func (proc *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
	}
	nim, err = process(nim, params)
	if err != nil {
		return nil, wrapParamError(err)
	}
	return nim, nil
}
Example #4
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
}
Example #5
0
// Process implements imageserver/image.Processor.
func (prc *Processor) Process(im image.Image, params imageserver.Params) (image.Image, error) {
	if !params.Has(param) {
		return im, nil
	}
	params, err := params.GetParams(param)
	if err != nil {
		return nil, err
	}
	im, err = prc.process(im, params)
	if err != nil {
		if err, ok := err.(*imageserver.ParamError); ok {
			err.Param = param + "." + err.Param
		}
		return nil, err
	}
	return im, nil
}
Example #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
}
Example #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
}
Example #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
}