I created a simple page who, with drag and drop create a new image and place the two dropped files into one and save it as jpg (or whatever).
The specs for an image is in the screen shot below (Preview / macOS).
I want to add a meta with the name of the two original file names in it, but I do not know how to do that by code.
Preview (apparently) allow something, mut manually.
Do not ask me from where the TIFF entry comes because I do not know.
My code create a Picture and print the two files in it, then save it to disk.
In the past when I’ve needed to write image metadata I shelled to exiftool. MBS has ExifTagsMBS but that is mostly for reading.
There is an entry in the Xojo Blog, but only for read them:
Looking into this sparked some curiosity and I have spent the last two days working on native xojo code to read/write exif metadata, and I now understand why there is not much out there for writing. This is a royal PITA.
I’m doing it all with memoryblocks. I still have a ways to go and my brain hurts so I’m calling it a night. No promises that I’ll end up with anything workable because I don’t know how much more time I can give it, but I’m trying.
2 Likes
Here is some mostly-working Exif Read code.
https://downloads.christianwheel.com/?xojoexif
I’m still struggling with writes. Getting the data types correct for each field is a pain and one mistake corrupts the whole tag, which can corrupt the whole file. Working on it, but no promises.
3 Likes
Hi, it will be great if you find a write Exif solution ! Can i help ?
Have you checkd the blog for the Write ?
I shared the link some entries before…
You had said the blog doesn’t write.
You are correct !
Wrong thinking ! I too wanted to be able to write meta entry(ies)…
Like Christian already said, Exiftool is probably your best bet. It does a decent job of writing meta data and can easily be invoked from the shell.
But first you must find a supported way of storing previous file names. The Exif standard doesn’t provide for this kind of info so you could only use XMP. Adobe Lightroom Classic, for example, stores the original name of a converted raw file in an XMP block. Keep in mind that most software won’t care about such meta data and won’t display it, just like the Mac’s Finder won’t show original file names preserved by Lightroom. Chances are you need to resort to Exiftool again to access it.
If you have access to MBS plugins, then you can use the full suite of XMP classes from Adobe. I find this method to be less clumsy than exiftool since the code is easier to read, but I’ve used both extensively and you can definitely use either one.
pure xojo code, no plugin no declare, can read and write.
MacOS
Windows11
Linux Ubuntu
1 Like
Reading a specific tag by name
Var meta As New VNSJPEGMetadata
If meta.ReadFromFile(myFile) Then
// Read simple string tags
Var cameraModel As String = meta.GetTag("Model").StringValue
Var dateTime As String = meta.GetTag("DateTimeOriginal").StringValue
// Read integer tags
Var width As Integer = meta.GetTag("PixelXDimension").IntegerValue
Var iso As Integer = meta.GetTag("ISOSpeedRatings").IntegerValue
Var flash As Integer = meta.GetTag("Flash").IntegerValue
// Read RATIONAL tags (returned as Pair = numerator : denominator)
Var focalLength As Variant = meta.GetTag("FocalLength")
If focalLength IsA Pair Then
Var p As Pair = Pair(focalLength)
Var mm As Double = p.Left.DoubleValue / p.Right.DoubleValue
// mm = 24.0 for a 24/1 focal length
End If
// Read exposure time (e.g. 1/125)
Var exposure As Variant = meta.GetTag("ExposureTime")
If exposure IsA Pair Then
Var p As Pair = Pair(exposure)
Var seconds As Double = p.Left.DoubleValue / p.Right.DoubleValue
End If
End If
Writing a simple string tag
Var meta As New VNSJPEGMetadata
If meta.ReadFromFile(inputFile) Then
// Set tags by name - the library places them in the correct IFD
meta.SetTag("Artist", "Jane Smith")
meta.SetTag("Copyright", "2026 Jane Smith")
meta.SetTag("ImageDescription", "Sunset at the beach")
// Save to a new file (non-destructive: original file is untouched)
Var outputFile As FolderItem = SpecialFolder.Desktop.Child("modified_photo.jpg")
If meta.WriteToFile(outputFile) Then
MessageBox("Saved successfully!")
Else
MessageBox("Error: " + meta.LastError)
End If
End If
1 Like
Hi, Sounds great !
I just want to read / write 2 Tags :
Orientation = &H112
DateTime = &H132
I can read them but i am not able to write.
Is it possible to share the method for read write these 2 tags ?
Thanks a lot
I am working on a little software that take pictures and videos and it batch resize them to make an index.html with all the photos and videos.
These 2 tags are very helpfull and i it will be great to keep these on saving miniatures.
Here is the link : Check Reduce for Web