I have a simple PHP script using imagecreatefromjpeg to create a thumbnail version of original and save it to a new folder. To speed parsing (all done in the back end prior to upload to static site) I am using file_exist before the creation to check it exists and show - if not create new and show. This works fine but if the original image changes the script does not generate as the thumbnail image exists in it's old form.
I guess I need to use MD5 test but as a n00b not sure how to test if the resulting thumbnail version would be different from the existing as produced by the main image.
Current Logic:
if thumb exist == do nothing,
if thumb does not exist == create it
Additional logic
if thumb will change due to change in original == create it,
if thumb will stay the same == do nothing
The existing PHP is very poor and clobbered together so happy for any pointers from a fresh (expert) view.
Thanks, John
You want to check the time the file was modified.
http://php.net/manual/en/function.filemtime.php
if the original file's timestamp is newer than the thumbnail's timestamp, then make a new thumbnail.
Thanks guys - not sure if that will work if the original image was created previously but only just being used eg stock images that are on file elsewhere and then dragged into the /images/ folder to replace existing image but with the same filename.. does the timestamp show the date dragged or when it was created?
If you move the files, the modified timestamp does not change.
If you copy the files, the copies are created by the copy action.
When you create a file, its Date Modified timestamp is the same as its Date Created timestamp.
So if your drag is copying the files, then the modified timestamp is the timestamp of the moment that the files were copied.