From 601396228884c94936a434eab47624bdaf33c87b Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Mon, 27 Nov 2017 05:54:10 +0000 Subject: [PATCH] better exif write only remove exif fields not on the image if we made the exif from the saved exif data on the image --- libvips/foreign/exif.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/libvips/foreign/exif.c b/libvips/foreign/exif.c index 138362a8..ee137159 100644 --- a/libvips/foreign/exif.c +++ b/libvips/foreign/exif.c @@ -1002,19 +1002,22 @@ vips_exif_update( ExifData *ed, VipsImage *image ) VIPS_DEBUG_MSG( "vips_exif_update: \n" ); - /* Walk the image and update any stuff that's been changed in image - * metadata. + /* Walk the image and add any exif- that's set in image metadata. */ vips_image_map( image, vips_exif_image_field, ed ); - /* Walk the exif and look for any fields which are NOT in image - * metadata. They must have been removed ... remove them from exif as - * well. + /* If this exif came from the image (rather than being an exif block we + * have made afresh), then any fields which are in the block but not on + * the image must have been deliberately removed. Remove them from the + * block as well. */ - ve.image = image; - ve.ed = ed; - exif_data_foreach_content( ed, - (ExifDataForeachContentFunc) vips_exif_exif_content, &ve ); + if( vips_image_get_typeof( image, VIPS_META_EXIF_NAME ) ) { + ve.image = image; + ve.ed = ed; + exif_data_foreach_content( ed, + (ExifDataForeachContentFunc) vips_exif_exif_content, + &ve ); + } } /* Examine the metadata tags on the image and update the EXIF block.