MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / parseGravity

Method parseGravity

options/parser/parse.go:342–397  ·  view source on GitHub ↗
(
	ctx context.Context,
	o *options.Options,
	key string,
	allowedTypes []processing.GravityType,
	args ...string,
)

Source from the content-addressed store, hash-verified

340}
341
342func (p *Parser) parseGravity(
343 ctx context.Context,
344 o *options.Options,
345 key string,
346 allowedTypes []processing.GravityType,
347 args ...string,
348) error {
349 nArgs := len(args)
350
351 keyType := key + keys.SuffixType
352 keyXOffset := key + keys.SuffixXOffset
353 keyYOffset := key + keys.SuffixYOffset
354
355 gType, err := p.parseGravityType(ctx, o, keyType, allowedTypes, args[0])
356 if err != nil {
357 return err
358 }
359
360 switch gType {
361 case processing.GravitySmart:
362 if nArgs > 1 {
363 return newInvalidArgsError(ctx, key, args)
364 }
365 o.Delete(keyXOffset)
366 o.Delete(keyYOffset)
367
368 case processing.GravityFocusPoint:
369 if nArgs != 3 {
370 return newInvalidArgsError(ctx, key, args)
371 }
372 fallthrough
373
374 default:
375 if nArgs > 3 {
376 return newInvalidArgsError(ctx, key, args)
377 }
378
379 if nArgs > 1 && len(args[1]) > 0 {
380 if x, err := strconv.ParseFloat(args[1], 64); err == nil && p.isGravityOffsetValid(gType, x) {
381 o.Set(keyXOffset, x)
382 } else {
383 return newInvalidArgumentError(ctx, keyXOffset, args[1])
384 }
385 }
386
387 if nArgs > 2 && len(args[2]) > 0 {
388 if y, err := strconv.ParseFloat(args[2], 64); err == nil && p.isGravityOffsetValid(gType, y) {
389 o.Set(keyYOffset, y)
390 } else {
391 return newInvalidArgumentError(ctx, keyYOffset, args[2])
392 }
393 }
394 }
395
396 return nil
397}
398
399func (p *Parser) parseExtend(

Callers 3

applyGravityOptionMethod · 0.95
applyCropOptionMethod · 0.95
parseExtendMethod · 0.95

Calls 6

parseGravityTypeMethod · 0.95
isGravityOffsetValidMethod · 0.95
newInvalidArgsErrorFunction · 0.85
newInvalidArgumentErrorFunction · 0.85
DeleteMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected