I have a
JPG image. I want to add/append a small piece of script(It can be of any language like
but the image extension should not be changed. It must be jpg itself even after appending the script and I want to view the image
in normal image viewers. Is it possible to achieve this?
I have a
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).
While you can hide something within a JPEG file, I'm afraid that adding a script that runs is not possible.
JPEG is a standard set out by Joint Photographic Experts Group, and these standards are now part of ISO standards. However in the standards there is no standard about "codes". That means most programs, if not all, would not understand the "code" you embedded in the JPEG file as it is no standard.
If you are trying to exploit security issues of certain JPEG reader, that's an other story... probably you will need a lot more research.