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)
| 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. |
| 215 | func 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. |
no test coverage detected