MCPcopy Index your code
hub / github.com/docker/docker-agent / transcodeImageWithMeta

Function transcodeImageWithMeta

pkg/chat/attach.go:215–226  ·  view source on GitHub ↗

transcodeImageWithMeta runs bytes through ResizeImage to normalise the image to JPEG or PNG within provider limits, then wraps the result in a Document. Returns the [ImageResizeResult] so callers can emit dimension notes.

(name string, data []byte, mimeType string)

Source from the content-addressed store, hash-verified

213// to JPEG or PNG within provider limits, then wraps the result in a Document.
214// Returns the [ImageResizeResult] so callers can emit dimension notes.
215func transcodeImageWithMeta(name string, data []byte, mimeType string) (Document, *ImageResizeResult, error) {
216 result, err := ResizeImage(data, mimeType)
217 if err != nil {
218 return Document{}, nil, fmt.Errorf("ProcessAttachment: transcode image %q: %w", name, err)
219 }
220 return Document{
221 Name: name,
222 MimeType: result.MimeType,
223 Size: int64(len(result.Data)),
224 Source: DocumentSource{InlineData: result.Data},
225 }, result, nil
226}
227
228// parseDataURI parses a data URI of the form "data:<mime>;base64,<payload>".
229// Returns the MIME type and decoded bytes.

Callers 3

processFilePartFunction · 0.85
processImageURLPartFunction · 0.85
processDocumentPartFunction · 0.85

Calls 1

ResizeImageFunction · 0.85

Tested by

no test coverage detected