#1 : 09/05-20 22:23 Zaibes
Posts: 1
|
Hello,
I was looking to have the pictures of my baby along with their age in the filename. Some people on the forum was looking for this, but could not find any script here. I thought it could be useful for the community. Just indicate the name of your kid along with his birth date at the bottom of the script and your good to go. Example: https://ibb.co/rbWj1yj Just copy paste the following snippet in the script method function ageDifference(dateString, datePicture) { var dob = new Date(dateString) var datePic = new Date(datePicture); if(datePic < dob) { var tmp = datePic datePic = dob dob = tmp } var datePicYear = datePic.getYear(); var datePicMonth = datePic.getMonth(); var datePicDay = datePic.getDate(); var yearDob = dob.getYear(); var monthDob = dob.getMonth(); var dateDob = dob.getDate(); var age = {}; var ageString = ""; var yearString = ""; var monthString = ""; var dayString = ""; yearAge = datePicYear - yearDob; if (datePicMonth >= monthDob) var monthAge = datePicMonth - monthDob; else { yearAge--; var monthAge = 12 + datePicMonth -monthDob; } if (datePicDay >= dateDob) var dateAge = datePicDay - dateDob; else { monthAge--; var dateAge = 31 + datePicDay - dateDob; if (monthAge < 0) { monthAge = 11; yearAge--; } } age = { years: yearAge, months: monthAge, days: dateAge }; if ( age.years > 1 ) yearString = " years"; else yearString = " year"; if ( age.months> 1 ) monthString = " months"; else monthString = " month"; if ( age.days > 1 ) dayString = " days"; else dayString = " day"; return age.years + yearString + " - " + age.months + monthString + " - " + age.days + dayString; } function isValidDate(dateString) { // First check for the pattern if(!/^\d{1,2}\/\d{1,2}\/\d{4}$/.test(dateString)) return false; // Parse the date parts to integers var parts = dateString.split("/"); var day = parseInt(parts[1], 10); var month = parseInt(parts[0], 10); var year = parseInt(parts[2], 10); // Check the ranges of month and year if(year < 1000 || year > 3000 || month == 0 || month > 12) return false; var monthLength = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ]; // Adjust for leap years if(year % 400 == 0 || (year % 100 != 0 && year % 4 == 0)) monthLength[1] = 29; // Check the range of the day return day > 0 && day <= monthLength[month - 1]; } var dateTimeOriginal = ( item.exifToolValue('DateTimeOriginal') == '' ) ? item.exifToolValue('ModifyDate') : item.exifToolValue('DateTimeOriginal') var y_original = dateTimeOriginal.substring(0,4) var m_original = dateTimeOriginal.substring(5,7) var d_original = dateTimeOriginal.substring(8,10) var datePicture = m_original + '/' + d_original + '/' + y_original var firstName = 'Oliver' var birthDate = '10/21/2016' var ageString = isValidDate(datePicture) ? ageDifference(birthDate, datePicture) : 'Unknown Age' return firstName + ' - ' + ageString + ' - ' + item.newBasename; |