I would like to generate a .JPG file that changes image based on the time of day. I know I could do this with PHP to swap out an image, but I would prefer to have it built into the image file. For instance, even if someone saved the image, it would still update according to the time. I found out how to pull EXIF original time, but how can i pull clock time? Furthermore, is there a way to program in logic to image files? For instance, if time is this, change the image to this? Any help would be appreciated.
-
Why use an image for text data? I feel like there's probably a better way to achieve whatever end result you're after. If you truly need it as an image you could have JavaScript swap the generated image at a given interval but I feel like this is probably the wrong approach. – Matt Mar 05 '15 at 01:50
-
I'm more interested in the image data than the text data. I simply want to display different images at different times of the day (morning, afternoon, night) – user3647894 Mar 05 '15 at 04:51
-
That gives so much more context as to what you're trying to do! In the simplest terms, use the appropriate image for the time of the day on the initial load. Swap them out with javascript when you hit one of the "time of day" changes. Overlay the image with the time if you want a clock of sorts. – Matt Mar 05 '15 at 13:59
-
@mkaatman thank you for the response! This is exactly what I would like to do, but not just in the browser. I realize I could easily do this with javascript but i am looking for a way to have this functionality built into the image file itself. For instance, even if you saved the image to your computer it would still show the correct image at the correct time of day when you open the image. – user3647894 Mar 05 '15 at 17:33
-
1You could do it with svg – Matt Mar 05 '15 at 18:06
-
Interesting...i will check into that. Thank you for your help! – user3647894 Mar 05 '15 at 18:07
1 Answers
No, you can not program logic into an image file - it's just data.
It's like programming a changing time into an English sentence saved to a file.
The current time is 00:00
There is just no programming involved.
See the sentence above?
It does not change - because it can not, obviously.
Now, lets take a screenshot of it, saved as a JPG file:
Just the same thing.
Ok, but what if we can change the EXIF data?
Let us look at the text file example again. Now, we use a file that has a metadata section, that contains the current time:
The current time is 00:00
------ Metadata: ------
Foo: bar
Time: 1:00
Of course, your text viewer would not show the metadata section normally, so it looks like before.
But you can set a second time value now. It's set to 1:00. Let's set it to 2:00:
The current time is 00:00
------ Metadata: ------
Foo: bar
Time: 2:00
Which still actually looks like this, when shown:
The current time is 00:00
You see my point - it does not do anything to write a time there.
Now, I'm not sure why we were using the EXIF data - maybe I missed it?

- 3,277
- 2
- 24
- 35
-
1
-
I found how to change EXIF values and also this interesting tutorial: http://php.webtutor.pl/en/2011/05/13/php-code-injection-a-simple-virus-written-in-php-and-carried-in-a-jpeg-image/ Could something like this be implemented? – user3647894 Mar 05 '15 at 01:09
-
As far as I can tell, what the link describes does not have much to do with JPG files, it would be more about hacking a PHP site - your own. – Volker Siegel Mar 05 '15 at 01:32