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:
@@ -355,9 +355,9 @@ pub async fn execute_read_image<W: UiWriter>(
|
||||
if resized_size < original_size {
|
||||
(resized, true)
|
||||
} 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");
|
||||
(bytes, original_dimensions.map(|(w, h)| w > MAX_IMAGE_DIMENSION || h > MAX_IMAGE_DIMENSION).unwrap_or(false))
|
||||
(bytes, false)
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
|
||||
Reference in New Issue
Block a user