From 010613c90986fd28ec7b210c45fbe07929725eeb Mon Sep 17 00:00:00 2001 From: hayato-SMZ Date: Wed, 26 Oct 2022 22:35:28 +0900 Subject: [PATCH] Issue393 (#552) * fix bug issue393 * Fixed to compare binary data * Change search criteria to compare ID with binary data --- docx-core/src/documents/mod.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) 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(); + } } } }