Process implements imagor.Processor interface
( ctx context.Context, blob *imagor.Blob, p imagorpath.Params, load imagor.LoadFunc, )
| 50 | |
| 51 | // Process implements imagor.Processor interface |
| 52 | func (v *Processor) Process( |
| 53 | ctx context.Context, blob *imagor.Blob, p imagorpath.Params, load imagor.LoadFunc, |
| 54 | ) (*imagor.Blob, error) { |
| 55 | ctx = withContext(ctx) |
| 56 | defer contextDone(ctx) |
| 57 | |
| 58 | // Use image cache for preview() requests: known-size, within cache max dims, no bypass conditions. |
| 59 | // preview() opts in to base image caching for interactive editing workflows. |
| 60 | // Skip for crop/focal/page/dpi: cache stores a downscaled single-page copy at default DPI. |
| 61 | if p.Image != "" && imagorpath.HasFilter(p, "preview") { |
| 62 | if _, isColor := parseColorImage(p.Image); !isColor { |
| 63 | sizeKnown := p.Width > 0 && p.Height > 0 |
| 64 | if sizeKnown && p.Width <= v.CacheMaxWidth && p.Height <= v.CacheMaxHeight && |
| 65 | !imagorpath.HasCacheBypass(p) && |
| 66 | blob.BlobType() != imagor.BlobTypeMemory { |
| 67 | if memBlob, _, cacheErr := v.loadOrCache(blob, p.Image, 1, nil); cacheErr == nil && memBlob != nil { |
| 68 | blob = memBlob |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | img, err := v.loadAndProcess(ctx, blob, p, load) |
| 75 | if err != nil { |
| 76 | return nil, err |
| 77 | } |
| 78 | defer img.Close() |
| 79 | |
| 80 | params := v.extractExportParams(p, blob, img) |
| 81 | v.applyAutoFormatFallback(img, params) |
| 82 | |
| 83 | // Handle metadata response |
| 84 | if p.Meta { |
| 85 | stripExif := imagorpath.HasFilter(p, "strip_exif") |
| 86 | var metaRegions []imagor.DetectorRegion |
| 87 | // Only run detection when the URL semantically requests it — smart crop, draw_detections() or redact() filter. |
| 88 | needsDetection := p.Smart || |
| 89 | imagorpath.HasFilter(p, "draw_detections") || |
| 90 | imagorpath.HasFilter(p, "redact") |
| 91 | if len(v.Detectors) > 0 && needsDetection { |
| 92 | metaRegions = v.detectRegions(ctx, img, p.Image) |
| 93 | } |
| 94 | m := metadata(img, params.format, stripExif, metaRegions) |
| 95 | for _, f := range p.Filters { |
| 96 | switch f.Name { |
| 97 | case "avgcolor": |
| 98 | if f.Args != "" { |
| 99 | return nil, imagor.NewError("avgcolor takes no arguments", 400) |
| 100 | } |
| 101 | color, err := avgColor(ctx, img) |
| 102 | if err != nil { |
| 103 | return nil, WrapErr(err) |
| 104 | } |
| 105 | m.AverageColor = color |
| 106 | case "blurhash": |
| 107 | args := imagorpath.SplitArgs(f.Args) |
| 108 | if len(args) != 2 { |
| 109 | return nil, imagor.NewError("blurhash requires exactly x and y components", 400) |