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

Method ProcessImage

processing/processing.go:61–143  ·  view source on GitHub ↗

ProcessImage processes the image according to the provided processing options and returns a [Result] that includes the processed image data and dimensions. The provided processing options may be modified during processing.

(
	ctx context.Context,
	imgdata imagedata.ImageData,
	o *options.Options,
)

Source from the content-addressed store, hash-verified

59//
60// The provided processing options may be modified during processing.
61func (p *Processor) ProcessImage(
62 ctx context.Context,
63 imgdata imagedata.ImageData,
64 o *options.Options,
65) (*Result, error) {
66 runtime.LockOSThread()
67 defer runtime.UnlockOSThread()
68
69 defer vips.Cleanup()
70
71 img := new(vips.Image)
72 defer img.Clear()
73
74 po := p.NewProcessingOptions(o)
75
76 // Load a single page/frame of the image so we can analyze it
77 // and decide how to process it further
78 thumbnailLoaded, err := p.initialLoadImage(img, imgdata, po.EnforceThumbnail())
79 if err != nil {
80 return nil, err
81 }
82
83 // Let's check if we should skip standard processing
84 if p.shouldSkipStandardProcessing(imgdata.Format(), po) {
85 return p.skipStandardProcessing(img, imgdata, po)
86 }
87
88 // Check if we expect image to be processed as animated.
89 // If MaxAnimationFrames is 1, we never process as animated since we can only
90 // process a single frame.
91 animated := po.MaxAnimationFrames() > 1 && img.IsAnimated()
92
93 // Determine output format and check if it's supported.
94 // The determined format is stored in po[KeyFormat].
95 outFormat, err := p.determineOutputFormat(img, imgdata, po, animated)
96 if err != nil {
97 return nil, err
98 }
99
100 // Now, as we know the output format, we know for sure if the image
101 // should be processed as animated
102 animated = animated && outFormat.SupportsAnimationSave()
103
104 // Load required number of frames/pages for processing
105 // and remove animation-related data if not animated.
106 // Don't reload if we initially loaded a thumbnail.
107 if !thumbnailLoaded {
108 if err = p.reloadImageForProcessing(img, imgdata, po, animated); err != nil {
109 return nil, err
110 }
111 }
112
113 // Check image dimensions and number of frames for security reasons
114 originWidth, originHeight, err := p.checkImageSize(img, imgdata.Format(), po)
115 if err != nil {
116 return nil, err
117 }
118

Callers 1

processImageMethod · 0.80

Calls 15

NewProcessingOptionsMethod · 0.95
initialLoadImageMethod · 0.95
EnforceThumbnailMethod · 0.95
MaxAnimationFramesMethod · 0.95
determineOutputFormatMethod · 0.95
checkImageSizeMethod · 0.95
transformImageMethod · 0.95
finalizePipelineMethod · 0.95
saveImageMethod · 0.95

Tested by

no test coverage detected