Write string EXIF-tags with libvips
See original GitHub issueHi,
I’ve got a problem with writing meta data to a JPEG file. I suppose this must be because of a datatype mismatch.
Here’s a little example program, where I experience this error:
var vipsImage = NetVips.Image.NewFromFile("test.jpg"); // Load iamge
System.Console.WriteLine("Old orientation: " + vipsImage.Get("orientation"));
vipsImage.Set("orientation", 2); // Change orientation
System.Console.WriteLine("New orientation: " + vipsImage.Get("orientation"));
System.Console.WriteLine("Old key words: " + vipsImage.Get("exif-ifd0-XPKeywords"));
vipsImage.Set("exif-ifd0-XPKeywords", "test keyword"); // Change key words
System.Console.WriteLine("New key words: " + vipsImage.Get("exif-ifd0-XPKeywords"));
vipsImage.Jpegsave("result.jpg"); // Write to file
var reloadedImage = NetVips.Image.NewFromFile("result.jpg"); // Reload file
System.Console.WriteLine("Orientation after reload: " + reloadedImage.Get("orientation"));
System.Console.WriteLine("Key words after reload: " + vipsImage.Get("exif-ifd0-XPKeywords"));
(Note: For the above code snippet to work, the Tags field in Properties => Details of the loaded JPEG file must at least have one tag set. Otherwise, of course, vipsImage.Get(“exif-ifd0-XPKeywords”) will fail)
and the corresponding output:
Old orientation: 1
New orientation: 2
Old key words: Test-Tag (Test-Tag, Byte, 18 components, 18 bytes)
New key words: test keyword
Orientation after reload: 2
Key words after reload: Test-Tag (Test-Tag, Byte, 18 components, 18 bytes)
As you can see, I’m able to set a new orientation in meta data and after saving the file to disk (doesn’t matter if I use Jpegsave or WriteToFile) and reloading the saved file again, the orientation still has my changed value but the exif-ifd0-XPKeywords field doesn’t. Now my guess is, this behavior is caused by a type mismatch of the exif-ifd0-XPKeywords field and the string i try to save into it. But the only hint I have is the different output of “Old keywords” and “New key words”. Looking at the byte information in the “Old key words”-output i suppose i have to save the “test keyword”-string in a different way. But I don’t know how. And also i don’t know why, because before saving the image to disc, the changes seem to have an effect.
By debugging I saw that the type of this field is GValue.RefStrType and the part of the method GValue.Set() for GValue.RefStrType equals the part for GValue.GStrType while the GValue.Get() method differs at this point.
Now my question: Is this an error in NetVips or is the error in front of my keyboard? 😃
I hope my problem is understandable and I’m thankful for any hint on how to properly save key words in the exif data. If you need any further information, don’t hesitate to ask.
Thank You
Issue Analytics
- State:
- Created 5 years ago
- Comments:15 (13 by maintainers)
Top GitHub Comments
OK, I think I’ve fixed
ImageDescription
.libexif has three different types of string write 😦 yuk!
I’ve just released NetVips 1.0.5 which bundle and depend upon libvips 8.7.