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

Method parseResolution

options/parser/parse.go:224–243  ·  view source on GitHub ↗

parseResolution parses a resolution option value in megapixels and stores it as pixels

(
	ctx context.Context,
	o *options.Options,
	key string,
	args ...string,
)

Source from the content-addressed store, hash-verified

222
223// parseResolution parses a resolution option value in megapixels and stores it as pixels
224func (p *Parser) parseResolution(
225 ctx context.Context,
226 o *options.Options,
227 key string,
228 args ...string,
229) error {
230 if err := p.ensureMaxArgs(ctx, key, args, 1); err != nil {
231 return err
232 }
233
234 f, err := strconv.ParseFloat(args[0], 64)
235 if err != nil || f < 0 {
236 return newInvalidArgumentError(ctx, key, args[0], "positive number or 0")
237 }
238
239 // Resolution is defined as megapixels but stored as pixels
240 o.Set(key, int(f*1000000))
241
242 return nil
243}
244
245// parseBase64String parses a base64-encoded string option value
246func (p *Parser) parseBase64String(

Calls 3

ensureMaxArgsMethod · 0.95
newInvalidArgumentErrorFunction · 0.85
SetMethod · 0.45

Tested by

no test coverage detected