mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-10-10 12:12:40 +02:00
Implement Max Bytes Filter (#275)
* Implement Max Bytes Filter * Update according to code review comments * Refactor according to code review comments
This commit is contained in:
committed by
Sergey Alexandrovich
parent
49aaecf464
commit
d74c402066
@@ -116,6 +116,7 @@ type processingOptions struct {
|
||||
Crop cropOptions
|
||||
Format imageType
|
||||
Quality int
|
||||
MaxBytes int
|
||||
Flatten bool
|
||||
Background rgbColor
|
||||
Blur float32
|
||||
@@ -193,6 +194,7 @@ func newProcessingOptions() *processingOptions {
|
||||
Gravity: gravityOptions{Type: gravityCenter},
|
||||
Enlarge: false,
|
||||
Quality: conf.Quality,
|
||||
MaxBytes: 0,
|
||||
Format: imageTypeUnknown,
|
||||
Background: rgbColor{255, 255, 255},
|
||||
Blur: 0,
|
||||
@@ -542,6 +544,20 @@ func applyQualityOption(po *processingOptions, args []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func applyMaxBytesOption(po *processingOptions, args []string) error {
|
||||
if len(args) > 1 {
|
||||
return fmt.Errorf("Invalid max_bytes arguments: %v", args)
|
||||
}
|
||||
|
||||
if max, err := strconv.Atoi(args[0]); err == nil && max >= 0 {
|
||||
po.MaxBytes = max
|
||||
} else {
|
||||
return fmt.Errorf("Invalid max_bytes: %s", args[0])
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func applyBackgroundOption(po *processingOptions, args []string) error {
|
||||
switch len(args) {
|
||||
case 1:
|
||||
@@ -744,6 +760,8 @@ func applyProcessingOption(po *processingOptions, name string, args []string) er
|
||||
return applyCropOption(po, args)
|
||||
case "quality", "q":
|
||||
return applyQualityOption(po, args)
|
||||
case "max_bytes", "mb":
|
||||
return applyMaxBytesOption(po, args)
|
||||
case "background", "bg":
|
||||
return applyBackgroundOption(po, args)
|
||||
case "blur", "bl":
|
||||
|
Reference in New Issue
Block a user