LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Embed string into JPEG files

Solved!
Go to solution

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

0 Kudos
Message 1 of 16
(4,121 Views)

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!

 

Spoiler
Read about using EXIF tags in Wikipedia!
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 16
(4,105 Views)

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.

 

AddEXIFtoJPEG.png

 

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.

Message 3 of 16
(4,086 Views)

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

0 Kudos
Message 4 of 16
(4,072 Views)

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!!!

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
Message 5 of 16
(4,070 Views)
Solution
Accepted by topic author Sable

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.

AddEXIFtoJPEG_ascii.png

Message 6 of 16
(4,060 Views)

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

0 Kudos
Message 7 of 16
(4,040 Views)

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.

0 Kudos
Message 8 of 16
(4,003 Views)

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

0 Kudos
Message 9 of 16
(3,986 Views)

@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...

0 Kudos
Message 10 of 16
(3,982 Views)