06-04-2019 02:07 PM
Hi,
Is there a way I can embed a text string into a JPEG file?
This string doesn't visibly appear on the image, instead it resides within the file and can be read back if I open the image file with a text editor - example Notepad.
- Sable
Solved! Go to Solution.
06-04-2019 02:42 PM
Hi Sable,
Is there a way I can embed a text string into a JPEG file? This string doesn't visibly appear on the image,
Yes!
06-04-2019 03:43 PM
Here is code I used a while ago to add a comment to a JPEG file. It will show up in the Details tab if you right-click in Windows Explorer and choose properties.
I seem to recall that the Microsoft folks thought they were being clever by not providing a constructor for a PropertyItem, this was meant to limit you to modifying existing tags. If there is not an existing comment tag I just grab the first property item and overwrite all of the fields to effectively create a new tag. If you are going to get Unicode-y with your comments then create an encoder object instead of just blowing up to U16.
06-04-2019 04:25 PM
Thanks Guys.
Darin.K,
1) Do you have the code in LabVIEW 2013 format?
2) Will the text string show up if we open the file in a text editor like Notpad?
- Sable
06-04-2019 04:29 PM
Where did you get the PropID number? I was using the list found here and couldn't get it to work.
That page says the comment field is 0x9286....not 0x9C9C.
Nice example!!!
06-04-2019 05:07 PM - edited 06-04-2019 05:16 PM
LV2013 Version attached. The metadata will show up in the file, it is not really obvious. I may try to get an ascii property to work if using Notepad is more important than viewing the property in Explorer.
I seem to recall getting the prop ID by manually adding a comment from Windows Explorer and then reading the properties using the .NET functions. I believe it is a Windoze-specific code, but the problem I had at the time was to get the comment field to show up.
Edit:
Using the description works with ascii, easier to find in the file itself. Shows up as the Title and Subject in Explorer.
06-05-2019 02:06 AM
Darin.K,
Awesome!
I don't see anything in explorer though, Right click image file - Properties - Details Tab > Title and Subject are blank. Are you using Windows 10?
But the text does show up on top within the image in ascii mode when read by notepad.
Question, is there a way I could insert the ascii comment at the end of the file instead of the beginning?
- Sable
06-05-2019 10:45 AM
I am a bitter clinger to Windows7, but I looked at a file on Win10 and the info I added shows up. If you have a specific file you want me to test, attach it. It is possible that if your file has no PropItems that it will fail.
The JPEG format uses markers so anything you write beyond the final marker will be ignored by a compliant viewer. You can simply append your text to the end of the file. Beware, this will be stripped anytime you save the file. The EXIF method is more robust that way. A low-level JPEG library could move that chunk to the end, but that is a big pain.
06-05-2019 01:06 PM
Noted on the potential issues with the text at the end. This EXIF is good enough for me.
Just for my understanding, how did you get the Title and Subject propid exactly?
- Sable
06-05-2019 01:25 PM
@Sable wrote:
Noted on the potential issues with the text at the end. This EXIF is good enough for me.
Just for my understanding, how did you get the Title and Subject propid exactly?
If it were me, I'd use a search-friendly pattern for the added data.
I found the propid using this link:
https://www.exiv2.org/tags.html
I just looked for an ascii encoded tag that looked reasonable. Don't go adding War and Peace to that tag...