fix(read_image): use correct media type when resize fails to reduce size

When resize_image_to_dimensions() returns a larger file than the original,
we fall back to using the original bytes. Previously, was_resized was set
to true if the original dimensions exceeded MAX_IMAGE_DIMENSION, which
caused final_media_type to be set to 'image/jpeg' even though we were
using the original PNG bytes.

This caused Anthropic API errors like:
  'Image does not match the provided media type image/jpeg'

Fix: Set was_resized=false when falling back to original bytes, so the
original media type (detected from magic bytes) is preserved.
This commit is contained in:
Dhanji R. Prasanna
2026-01-22 07:58:05 +05:30
parent 022f5c70a6
commit af8b849311

View File

@@ -355,9 +355,9 @@ pub async fn execute_read_image<W: UiWriter>(
if resized_size < original_size { if resized_size < original_size {
(resized, true) (resized, true)
} else { } else {
// Resize didn't help, use original but warn if it's huge // Resize didn't help, use original bytes with original media type
debug!("Resize didn't reduce size, using original"); debug!("Resize didn't reduce size, using original");
(bytes, original_dimensions.map(|(w, h)| w > MAX_IMAGE_DIMENSION || h > MAX_IMAGE_DIMENSION).unwrap_or(false)) (bytes, false)
} }
} }
Err(e) => { Err(e) => {