There's something you can do with the Windows copy
facility and a RAR archive, which might suit what you're looking for. Get a JPG and a RAR and run the following command in the Windows command prompt:
copy /b image.jpg + archive.rar finalimage.jpg
This will produce a JPG image that can be opened using the WinRAR archiver to reveal files inside. It works because the RAR format is such that any program designed to handle the archives will scan through the headers of any binary file and only engage once it finds the "Rar!" header. As a result, you can place a "Rar!" header after another file (in this case a JPG, but it also works for MP3 files) without damaging the data of either file.
Under a unix operating system this can be achieved with the cat command as shown.
cat image.jpg archive.rar > finalimage.jpg
In regards to your initial question, I sincerely hope your intention was not to produce a JPG that would contain a script that would be executed by users upon viewing the image, or as some sort of 21st-century user-hostile copy-protection, as time has demonstrated again and again that such methods not only cause considerable backlash but often serve only to irritate the people who are giving you legitimate custom (with pirated versions of your material often having the offending protection either neutered or stripped out entirely).
3A little background or the goal you are trying to reach with this construction would be appreciated. – Pavel – 2014-08-13T11:13:55.753
@PavelPetrman its for some kind of tracking purpose:) – Mad Angle – 2014-08-27T03:47:05.157