Open ZIP file

Create your own scripts by clicking 'Show script view' in the top right corner or select one of the preset scripts from below.

Description

This preset fixes the date taken field for images that are restored from backup for WhatsApp on Android. See the following article for more information.


Run custom scripts

WARNING - Running custom scripts in your browser can be DANGEROUS. Do not copy paste and run scripts if you do not know what they are doing and/or are from a source you do not trust. I do not take any responsbility for damage or harm caused by using this tool.


{
  settings: {
    re: /(.jpg|.png|.gif|.jpeg)$/,
    pad: function pad(n, width, z) {
      z = z || '0';
      n = n + '';
      return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
    }
  },
  process: (relativePath, entry, content, newZip, settings) => {
    let dateStr = relativePath.split(/[_-]/)[1];
    let year = parseInt(dateStr.substring(0, 4));
    let month = parseInt(dateStr.substring(4, 6));
    let day = parseInt(dateStr.substring(6));
    if (settings.re.test(entry.name)) {
      const exif = load(content);
      if (exif.Exif) {
        if (!exif.Exif[TagValues.ExifIFD.DateTimeOriginal]) {
          exif.Exif[TagValues.ExifIFD.DateTimeOriginal] = year + ":" + settings.pad(month, 2) + ":" + settings.pad(day, 2) + " 00:00:00";
        }
      } else {
        exif.Exif = {
          [TagValues.ExifIFD.DateTimeOriginal]: year + ":" + settings.pad(month, 2) + ":" + settings.pad(day, 2) + " 00:00:00",
        };
      }
      const exifBytes = dump(exif);
      content = insert(exifBytes, content);
    }
    newZip.file(entry.name, content, { binary: true, date: new Date(year, month - 1, day, 12, 0, 0) });
  }
}
1234567891011121314151617181920212223242526272829303132