diff --git a/docx-core/src/documents/mod.rs b/docx-core/src/documents/mod.rs index e6cb188..c348487 100644 --- a/docx-core/src/documents/mod.rs +++ b/docx-core/src/documents/mod.rs @@ -920,13 +920,20 @@ fn collect_images_from_paragraph( for child in &mut run.children { if let RunChild::Drawing(d) = child { if let Some(DrawingData::Pic(pic)) = &mut d.data { - images.push(( - pic.id.clone(), - // For now only png supported - format!("media/{}.png", pic.id), - )); let b = std::mem::take(&mut pic.image); - image_bufs.push((pic.id.clone(), b)); + let buf = image_bufs + .iter() + .find(|x| x.0 == pic.id.clone() || x.1 == b.clone()); + if buf.as_ref().is_none() { + images.push(( + pic.id.clone(), + // For now only png supported + format!("media/{}.png", pic.id), + )); + image_bufs.push((pic.id.clone(), b)); + } else { + pic.id = buf.unwrap().0.clone(); + } } } }