To what degree, if at all, can custom code be embedded in a PNG, GIF, or JPG? Computer graphics files are in Windows rendered by components such as the Graphics Device Interface and Direct2D.

Is it possible to create a graphic file that, besides displaying a graphic also utilizes custom code inside the graphic file?

With custom code I am referring to functionality such as:


Incrementing a counter or date that is displayed on the graphic.
Accessing a web URL to retrieve data that is displayed on the graphic.
Common graphics formats such as JPEG, PNG and GIF are not designed to have any form of code inside them. They just store a compressed array of pixels&mdash;they can't generate anything on command or contact a web service, etc.

(There have occasionally been vulnerabilities discovered in image decoders, that would allow a maliciously constructed image to cause code execution when viewed, via a buffer overflow exploit or similar. But this is of course not part of the design of the format.)

Some vector graphics formats such as EPS and SVG actually do allow embedding code. However, being vector formats instead of bitmap ones, these formats often aren't supported by ordinary image viewers (although SVG is supported by browsers), and can't be edited in ordinary paint programs. One needs specialized vector graphics programs to work with them.

In order to generate an image that updates with new data, you could create a web service that regenerates the image on the server each time it's requested. However, if a client caches the resulting image rather than re-requesting it each time it's viewed, they would see old data.