Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Writing EXIF #167

Closed
jeromenelson opened this issue May 9, 2022 · 5 comments
Closed

Question: Writing EXIF #167

jeromenelson opened this issue May 9, 2022 · 5 comments
Labels
bug Something isn't working
Milestone

Comments

@jeromenelson
Copy link

Hello there,

Hoping this is a quick one. How to insert IFD2/Lens tags into an image? I was able to set many other tags without any issues, anything related to Lens info (exif-ifd2-LensModel, exif-ifd2-LensSpecification, exif-ifd2-LensSerialNumber, exif-ifd2-LensMake) does not seem to work.

            using var image = NetVips.Image.NewFromFile(Path.Join(_path, "img_no_exif.jpg"));
            image.Mutate(m => m.Set(GValue.GStrType, "exif-ifd2-LensMake", "Canon"));
            image.WriteToFile(Path.Combine(_path, "img_with_lens_info.jpg"));

            using var exifed = NetVips.Image.NewFromFile(Path.Join(_path, "img_with_lens_info.jpg"));
            bool hasLensMake = exifed.Contains("exif-ifd2-LensMake");

Side note: I tried both GValue.GStrType and GValue.RefStrType with no luck. For other tags, I figured out how to successfully set certain values through trial and error - for example, while working with other numeric fields (say exif-ifd2-FNumber), instead of directly using GValue.GDoubleType I had to convert it to a rational string and then use the type GValue.RefStrType to successfully set. But this simple string field, I just can't get to the bottom of it.

Thank you in advance!

@kleisauke kleisauke added bug Something isn't working blocked-upstream-dependency Upstream dependency needs to be updated labels May 9, 2022
kleisauke added a commit to kleisauke/libvips that referenced this issue May 9, 2022
Make `tag_is_ascii` aware of the EXIF 2.3 ASCII tags that are
available since libexif 0.6.22.

See: kleisauke/net-vips#167
@kleisauke
Copy link
Owner

Hi @jeromenelson,

These ASCII tags were added in the EXIF 2.3 specification, which libvips is currently unaware of. I've just opened PR libvips/libvips#2795 that allows you to modify/create these tags in libvips. After that, this should work without any problems:

using var image = Image.NewFromFile("x.jpg");
using var mutated = image.Mutate(m => m.Set(GValue.GStrType, "exif-ifd2-LensMake", "Canon"));
mutated.WriteToFile("x2.jpg");

using var image2 = Image.NewFromFile("x2.jpg");
Debug.Assert(image2.Contains("exif-ifd2-LensMake"));

@jeromenelson
Copy link
Author

Thank you for the quick response, any idea how long would it take for this PR to make it into the next release?

jcupitt pushed a commit to libvips/libvips that referenced this issue May 10, 2022
* Allow to modify/create EXIF 2.3 ASCII tags

Make `tag_is_ascii` aware of the EXIF 2.3 ASCII tags that are
available since libexif 0.6.22.

See: kleisauke/net-vips#167

* Fix CI
@kleisauke
Copy link
Owner

We aim for a release in late May, see: libvips/libvips#2790. Setting exif-ifd2-LensSpecification should be possible after PR libexif/libexif#85, e.g.:

using var image = Image.Black(100, 100);
using var mutated = image.Mutate(m => m.Set(GValue.GStrType, "exif-ifd2-LensSpecification", "5/1 10/1 100/1 200/1"));
mutated.WriteToFile("x2.jpg");

using var image2 = Image.NewFromFile("x2.jpg");
Debug.Assert(image2.Contains("exif-ifd2-LensSpecification"));

@kleisauke kleisauke added this to the 2.2.0 milestone Jul 25, 2022
@kleisauke kleisauke removed the blocked-upstream-dependency Upstream dependency needs to be updated label Jul 25, 2022
@kleisauke
Copy link
Owner

NetVips v2.2.0 and NetVips.Native v8.13.0 is now available.

Note that setting exif-ifd2-LensSpecification would require libexif to be built from the master branch, the pre-built binaries provided by NetVips are built against libexif v0.6.24.

@jeromenelson
Copy link
Author

Thank you, super excited about the other new features as well!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants