MCPcopy Create free account
hub / github.com/diillson/chatcli / loadInputImages

Function loadInputImages

cli/plugins/builtin_image.go:261–282  ·  view source on GitHub ↗

loadInputImages reads the given file paths into imagegen.Image values, inferring the MIME/extension from the bytes.

(paths []string)

Source from the content-addressed store, hash-verified

259// loadInputImages reads the given file paths into imagegen.Image values,
260// inferring the MIME/extension from the bytes.
261func loadInputImages(paths []string) ([]imagegen.Image, error) {
262 out := make([]imagegen.Image, 0, len(paths))
263 for _, p := range paths {
264 data, err := os.ReadFile(p) //#nosec G304 -- user/agent-specified image path for @image edit
265 if err != nil {
266 return nil, fmt.Errorf("read %q: %w", p, err)
267 }
268 mime, ok := models.DetectImageMediaType(data)
269 if !ok {
270 return nil, fmt.Errorf("%q is not a supported image", p)
271 }
272 ext := strings.TrimPrefix(filepath.Ext(p), ".")
273 if ext == "" {
274 ext = strings.TrimPrefix(mime, "image/")
275 }
276 out = append(out, imagegen.Image{Data: data, Mime: mime, Ext: ext})
277 }
278 if len(out) == 0 {
279 return nil, errors.New("no readable input images")
280 }
281 return out, nil
282}
283
284// writeImages saves the images. With one image and an out file path, it writes
285// there; otherwise it writes into out (a directory) or temp files.

Callers 1

ExecuteWithStreamMethod · 0.85

Calls 2

DetectImageMediaTypeFunction · 0.92
ErrorfMethod · 0.80

Tested by

no test coverage detected