How to Extract Creation Time / Date of .jpg Image from Linux WebServer ?


This is what I've been trying to do:
I've been stuck trying to do this for some days now. It doesn't seem like its very difficult, but for some reason I haven't been able to figure it out.

I'm working on a project where I need a .jpg image is sent from a Canon S400 camera to a custom application which processes it (for cropping etc.), which is then ftp'd to a LINUX Web Server (the image is copied to another .jpg file), and is then displayed on the webpage.

Now, the problem is that, presently, the time being displayed under the image is the time from the local host it changes from machine to machine. I want the time the image was taken from the camera, i.e., the time the picture was taken, which I believe is available in the image header file.

I would appreciate if someone could help me with this. I'm not sure if there's an in-built Javascript function to do this, but just to re-iterate, what needs to be done is to extract the date / time the image was created from the header file, and display it on the webpage.

I did get some replies to this E-mail but I don't think this can be done using Javascript, on the client side.

However, I do believe that this can be done by extracting the creation date and time of the image from the file system structure (that contains directory information for each file stored on the hard disk). Since the .jpg image will be stored in the file system, I need to find the operating system call that will return the creation date and time from the file system structure. By the way, just to reiterate, its a LINUX Web Server.

It would be great if someone could reply to this asap with the system call for doing this, and the code in Java (or some other script / language), with which the time / date could be displayed on the webpage.

Thanks a million.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

the linux file system stores A-C-M attributes of a file.
Access time - last time the file was accessed
Change time - last time some metadata was changed i.e. permissions
Modification time- last time the actual file was changed.

There unfortunately is no native stat in the linux filesystem which stores the creation time of the file.  Most of the time either the change or modification may be the creation time, but that is not gaurenteed.
All information can be access via the 'stat' command in redhat linux. (-lu, -l and -lc ) on other systems

As for the date in an jpg header, i am almost postive that jpgs do no store any date information in their header.  I created created 2 jps at 2 different times, and did a diff ( bit by bit comparision) which resulted in no difference.

hope this helps

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
If you can extract the image timestamp from the jpg file, you can then
use the 'touch' command to modify the timestamp of the file.

I don't know much about Linux, but I have a IXUS400 with the window software which can put the photos in oder by the date. I think you can do whatever you want if you have the photos in different "date" folders.
sapan_desaiAuthor Commented:

I haven't been able to figure this out yet. Can someone please help me write a Linux Script, which I can use with JSP, to extract the File Modified, Access, or Change Date and Time for the .jpg file and display it on the webpage. I need the date and time for the image when the camera application last sent the image over to the web server.

It would be really helpful if someone has a good understanding of JSP and can help me write the entire code to do the above.


Hey sapan,

I don't have access to a jsp server but, here's what I wrote which might help you out.

<%@ page import="java.util.*, java.text.*,*" %>

 File filems = new File("./pathtojpg.jpg");
long timems = filems.lastModified();
Date datems = new Date(timems);

Hope this helps
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.