Store the last-modified timestamp when the user begins editing an image. when they submit their changes, check against the last-modified timestamp again. If it's different, inform the user than another user has already modified the image.
You might want to let the user see the new version of the image before choosing to overwrite. Also, you may want to provide a version control system (a la wikipedia) to let people roll back changes.
EDIT (In response to comments below)
As opposed to storing the last modified time stamp (or perhaps in addition to), store a hash of the original image. and compare those immediately before overwriting. Otherwise same as above.
The other option, as you suggested would also work well. at step 3 in your workflow create an [imagefilename].lock file (or modify a field in the DB if they are stored there) at the beginning of the process if one doesn't already exist, of course if one does exist, then same as above.
To expand on the DB option in point 2 above, it would be much simpler to have a table like:
image_id | image_data
query including the md5 when you begin (optionally compute the md5 in php instead to reduce load on your db)
select image_data, md5(image_data) from image_table where image_id=1
Then when you want to write back, do
update image_table set image_data=? where image_id=? and md5(image_data)=?
This makes the update conditional on the md5 being identical before being overwritten, and it remains in a single, simple query.
Then check the affected_rows. If no rows were affected, then check the hash. If the hash is different then presumably the query failed to update due to the md5 check. (Note: you will probably also want to check for any mysql errors)