Missing EXIF tags could make your android gallery look bad
I recently helped migration to an new android phone. One part of the process was to store old (WhatsApp) stored images on internal storage towards the external storage SD Card.
Installing the new phone revealed an unexpected fall-out of having all the old pictures being sorted as being taken today.
Close inspection revieved Android Media Store uses the EXIF CreateDate to store the moment the picture was taken, missing the tag, it will use the file modification date as backup. How-ever this modification date of course was reset, because the file was copied from internal storage, without preserving the file modification dates.
The first attempt of fixing the issue was by turning off the phone, removing the SD card and fix the modification time of every file, based on the date identifier found in the file e.g. $ touch -a -m -t 201906230000 IMG-20190623-WA001.jpg
.
After an re-insert of SD and turning the phone back on, it was not fixing anything. Basically the re-indexing needed to be forced. This is best done by removing all data from the 'Media Storage' System App. Go to Settings -> Apps -> "3 dots button" -> "Show System Apps" -> "Media Storage" -> Storage -> "Clear Data" -> OK
. And next reboot the phone and open the images overview on the SD card using Settings -> "Device Care" -> Storage -> "SD Card" -> "Images"
. Depending on the amount of pictures this could take a while before your device is responsive again.
So finally all pictures and videos are indexed again and the Gallery shows pictures and videos in good order again. All happy right? ... but wait what about Facebook App ... personally I would nuke it and never look back, how-ever some people do not care about being 'the product' and will happily 'pay' for the service by providing lots of personal data. Having this said, I like a good engineering puzzle, so let's get started.
Facebook App (and maybe others) are still showing pictures garbled, which is annoying when for example wanting to upload older pictures, since you have to scroll down a long while before getting to the good stuff again. Apparently facebook does not rely on the metadata generated by the "MediaStore" and generates it's own, how-ever it blindly ignores the file modified date if EXIF data is missing and simply tags the picture as being taken the moment it is indexed. So how-to fix it?
First and foremost we need help, by some very powerful software EXIFTool, this will help us create the required EXIF tags based on the date string found in the filename. So turn off the phone again and plug the SD Card into a computer ones more.
We are going to use this magic:
$ exiftool \ "-datetimeoriginal-=" \ '-datetimeoriginal<${filename;$_=substr($_,4,8)} 00:00' \ "-createdate-=" \ '-createdate<${filename;$_=substr($_,4,8)} 00:00' \ '-filemodifydate<${filename;$_=substr($_,4,8)} 00:00' IMG-*WA*
To explain a little:
- Do not update DateTimeOriginal EXIF tag if already exists:
"-datetimeoriginal-="
- Base the DateTimeOriginal EXIF tag on the filename, by selecting the 5th until 12th character in the filename and expanding this with time midnight (00:00). This special rule is required to ensure file named like IMG-20190405-WA-1290.jpg could be parsed without issues, normal syntax is causing 90 to be specified as minutes which causes errors on importing.
'-datetimeoriginal<${filename;$_=substr($_,4,8)} 00:00'
- Same applies for EXIF CreateDate:
"-createdate-=" \ '-createdate<${filename;$_=substr($_,4,8)} 00:00' \
- our previous
$ touch
equivalent is a nice-to-have yet not required:
'-filemodifydate<${filename;$_=substr($_,4,8)} 00:00' IMG-*WA*
Now, put your SD card back in the phone and turn it back on. Clear your facebook data "Settings -> Apps -> Facebook -> "Clear Data" -> "Ok'
and restart your Facebook Apps and wait a long time again. After your phone (literally) cools down it's time to enjoy the result.
Comments
No comments.