mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-04-07 06:50:09 +02:00
Ability to skip processing of some formats
This commit is contained in:
parent
fa4dd9f346
commit
08dc814e98
@ -2,6 +2,7 @@
|
||||
|
||||
## [Unreleased]
|
||||
### Added
|
||||
- Ability to skip processing of some formats. See [Skip processing](https://docs.imgproxy.net/#/configuration?id=skip-processing).
|
||||
- (pro) [video_thumbnail_second](https://docs.imgproxy.net/#/generating_the_url_advanced?id=video-thumbnail-second) processing option.
|
||||
- (pro) [background_alpha](https://docs.imgproxy.net/#/generating_the_url_advanced?id=background-alpha) processing option.
|
||||
|
||||
|
21
config.go
21
config.go
@ -58,6 +58,23 @@ func boolEnvConfig(b *bool, name string) {
|
||||
}
|
||||
}
|
||||
|
||||
func imageTypesEnvConfig(it *[]imageType, name string) {
|
||||
*it = []imageType{}
|
||||
|
||||
if env := os.Getenv(name); len(env) > 0 {
|
||||
parts := strings.Split(env, ",")
|
||||
|
||||
for _, p := range parts {
|
||||
pt := strings.TrimSpace(p)
|
||||
if t, ok := imageTypes[pt]; ok {
|
||||
*it = append(*it, t)
|
||||
} else {
|
||||
logWarning("Unknown image format to skip: %s", pt)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func hexEnvConfig(b *[]securityKey, name string) error {
|
||||
var err error
|
||||
|
||||
@ -187,6 +204,8 @@ type config struct {
|
||||
EnforceWebp bool
|
||||
EnableClientHints bool
|
||||
|
||||
SkipProcessingFormats []imageType
|
||||
|
||||
UseLinearColorspace bool
|
||||
DisableShrinkOnLoad bool
|
||||
|
||||
@ -329,6 +348,8 @@ func configure() error {
|
||||
boolEnvConfig(&conf.EnforceWebp, "IMGPROXY_ENFORCE_WEBP")
|
||||
boolEnvConfig(&conf.EnableClientHints, "IMGPROXY_ENABLE_CLIENT_HINTS")
|
||||
|
||||
imageTypesEnvConfig(&conf.SkipProcessingFormats, "IMGPROXY_SKIP_PROCESSING_FORMATS")
|
||||
|
||||
boolEnvConfig(&conf.UseLinearColorspace, "IMGPROXY_USE_LINEAR_COLORSPACE")
|
||||
boolEnvConfig(&conf.DisableShrinkOnLoad, "IMGPROXY_DISABLE_SHRINK_ON_LOAD")
|
||||
|
||||
|
@ -174,6 +174,16 @@ You can set up a fallback image that will be used in case imgproxy can't fetch t
|
||||
* `IMGPROXY_FALLBACK_IMAGE_PATH`: path to the locally stored image;
|
||||
* `IMGPROXY_FALLBACK_IMAGE_URL`: fallback image URL.
|
||||
|
||||
## Skip processing
|
||||
|
||||
You can configure imgproxy to skip processing of some formats:
|
||||
|
||||
* `IMGPROXY_SKIP_PROCESSING_FORMATS`: list of formats that imgproxy shouldn't process, comma-divided.
|
||||
|
||||
**📝Note:** Processing can be skipped only when the requested format is the same as the source format.
|
||||
|
||||
**📝Note:** Video thumbnails processing can't be skipped.
|
||||
|
||||
## Presets
|
||||
|
||||
Read about imgproxy presets in the [Presets](presets.md) guide.
|
||||
|
@ -186,6 +186,21 @@ func handleProcessing(reqID string, rw http.ResponseWriter, r *http.Request) {
|
||||
|
||||
checkTimeout(ctx)
|
||||
|
||||
if len(conf.SkipProcessingFormats) > 0 {
|
||||
imgdata := getImageData(ctx)
|
||||
po := getProcessingOptions(ctx)
|
||||
|
||||
if imgdata.Type == po.Format || po.Format == imageTypeUnknown {
|
||||
for _, f := range conf.SkipProcessingFormats {
|
||||
if f == imgdata.Type {
|
||||
po.Format = imgdata.Type
|
||||
respondWithImage(ctx, reqID, r, rw, imgdata.Data)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
imageData, processcancel, err := processImage(ctx)
|
||||
defer processcancel()
|
||||
if err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user