What I can see is that you need to include metadata in an accepted format for images, for instance EXIF.
img = Image[Rasterize[x], MetaInformation -> {"Exif" -> {"ImageDescription" -> "An example", "Make" -> "camera brand", "Model" -> "xxx"}}] Export["test2.jpg", img] Import["test2.jpg", "ImageWithExif"] Options[%, MetaInformation] {MetaInformation -> {"Exif" -> {"ImageDescription" -> "An example",
"Make" -> "camera brand", "Model" -> "xxx"}}} The fields that EXIFEXIF accepts are limited, but there is a field called UserComment of arbitrary length and format.
Your example code does not work, so I will do a minimum working example with random data
Export[ "testimage.jpg" , Image[ Import["ExampleData/lena.tif"] , MetaInformation -> {"Exif" -> {"UserComment" -> RandomInteger[255, 1024 1024]}} ]] To recover:
Options[Import["testimage.jpg", "ImageWithExif"], MetaInformation] EDIT
You could encode anything you want as a list of integers, for instance using Compress and ToCharacterCode
storeInImage[img_Image, data_] := Image[img, MetaInformation -> {"Exif" -> {"UserComment" -> ToCharacterCode[Compress[data]]}} ] extractFromImage[img_Image] := Uncompress[ FromCharacterCode@ Association[Nest[Values, Options[img, MetaInformation], 2]][[ "UserComment"]]] storeInImage[Import["ExampleData/lena.tif"], ExampleData[{"Text", "ToBeOrNotToBe"}]] extractFromImage[%]
To be, or not to be,--that is the question:-- Whether 'tis nobler in
the mind [...]
