ResizeImageBase64 is a convenience wrapper around ResizeImage that accepts and returns base64-encoded image data. The base64-encoded result is returned separately to avoid mutating the ImageResizeResult.Data field.
(b64Data, mimeType string)
| 181 | // and returns base64-encoded image data. The base64-encoded result is returned |
| 182 | // separately to avoid mutating the ImageResizeResult.Data field. |
| 183 | func ResizeImageBase64(b64Data, mimeType string) (b64Result string, metadata *ImageResizeResult, err error) { |
| 184 | raw, err := base64.StdEncoding.DecodeString(b64Data) |
| 185 | if err != nil { |
| 186 | return "", nil, fmt.Errorf("decode base64: %w", err) |
| 187 | } |
| 188 | result, err := ResizeImage(raw, mimeType) |
| 189 | if err != nil { |
| 190 | return "", nil, err |
| 191 | } |
| 192 | return base64.StdEncoding.EncodeToString(result.Data), result, nil |
| 193 | } |
| 194 | |
| 195 | // FormatDimensionNote produces a human-readable note describing the resize mapping. |
| 196 | // This helps the model translate coordinates from the resized image back to the original. |