c2pa-rs

A fork of https://github.com/contentauth/c2pa-rs/
git clone git://archive.git.mtrnord.blog/mtrnords-photography-manager/c2pa-rs.git
Log | Files | Refs | README

commit 27e2690fc8531e09d11b591fe51ec32bb93fb938
parent 7c1b0c355ee465bc4d01337a62e3e463d5333dad
Author: Gavin  Peacock <gpeacock@adobe.com>
Date:   Thu, 27 Oct 2022 16:54:34 -0700

Fix manifest.set_thumbnail when add_thumbnails is enabled (#148)

* Fix overriding manifest thumbnail
Diffstat:
Msdk/src/manifest.rs | 27++++++++++++++++++++++++---
1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/sdk/src/manifest.rs b/sdk/src/manifest.rs @@ -536,9 +536,12 @@ impl Manifest { self.set_title(ingredient.title()); } - #[cfg(feature = "add_thumbnails")] - if let Ok((format, image)) = crate::utils::thumbnail::make_thumbnail(path.as_ref()) { - self.set_thumbnail(format, image); + // if a thumbnail is not already defined, create one here + if self.thumbnail().is_none() { + #[cfg(feature = "add_thumbnails")] + if let Ok((format, image)) = crate::utils::thumbnail::make_thumbnail(path.as_ref()) { + self.set_thumbnail(format, image); + } } } @@ -1219,4 +1222,22 @@ pub(crate) mod tests { "XCAplus.jpg" ); } + + #[cfg(feature = "file_io")] + #[test] + fn test_embed_user_thumbnail() { + let temp_dir = tempdir().expect("temp dir"); + let output = temp_fixture_path(&temp_dir, TEST_SMALL_JPEG); + + let signer = temp_signer(); + + let mut manifest = test_manifest(); + manifest.set_thumbnail("image/jpeg", vec![1, 2, 3]); + manifest.embed(&output, &output, &signer).expect("embed"); + let manifest_store = crate::ManifestStore::from_file(&output).expect("from_file"); + let active_manifest = manifest_store.get_active().unwrap(); + let (format, thumb) = active_manifest.thumbnail().unwrap(); + assert_eq!(format, "image/jpeg"); + assert_eq!(thumb, vec![1, 2, 3]); + } }