Firstly a quick explanation of what I am trying to accomplish.
We have 30.000 photos, and I am trying to convert them & all incoming future photos to a different file type, resize them and add a watermark while keeping the original.
So far I have a script I found online that can sync all photos between 2 folders so that the original is kept. the sync works by comparing the filename and the timestamp.
the sync script copies the file exactly, so keeps the original time stamp - so if I edit the original photo and the timestamp thereby changes, those changes are synced.
After the sync, I have a script that throws a command into CMD, activating some software called ImageMagick, that does all the photo manipulation in the background.
However, the issue is that when ImageMagick has done its... Magic, the file has then changed it's timestamp - and since there is a filetype change, and to separate the unprocessed photos from the processed, they also have a change of filename (from photo.jpg to photo_watermark.webp)
But when I want to combine the script into one, that can do all of the actions (preferably to run hourly or daily), I cannot wrap my head around how to do it.
I need to reinstate the original timestamp (I can use FileSetTime) - but I somehow have to have the script take the timestamp from photo.jpg and have it used on photo_watermark.webp
Also the sync script, I have to tell it that photo.jpg is the same file as photo_watermark.webp - I assume I can do something here with stringreplace
Can someone help a fellow about to give up?
Code pasted below:
Image manipulation:
Code: Select all
myFolder :=""
FileSelectFolder, myFolder ; prompt to selct a folder, save it as myFolder
Loop, Files, %myFolder%\*.jpg ; this will only loop thru the non watermarked files
{
Run cmd.exe /c magick composite -tile C:\Users\kpe\Desktop\Herfra\watermark_white.png -resize 50`% C:\Users\kpe\Desktop\Herfra\%A_LoopFileName% C:\Users\kpe\Desktop\Hertil\%A_LoopFileName%_watermark.webp ;runs CMD and has imagemagick add a watermark, resize the photo and convert it to webp
}
Code: Select all
; supersynchronizer
; :: SuperSynchronizer, a little script for incremental/mirror directory backup.
; ----------------------------------
; cyrusza - http://ciroprincipe.info
; --
; :: Set the source and destination directory, set copy mode and let the script work.
; :: To exclude files from the replication or reverse check, add them to the exclusion lists.
; ----------------------------------
; --
#SingleInstance force
; SOURCE/DESTINATION DIRECTORIES
; ***************************************************************
;
; Change these values for source and destination directories.
;
; Rules:
; ------
; [absolute path]
; [no quotes]
;
; Examples:
; ---------
; SS_sourceDir = C:\a_dir\a_subdir\a_source_subdir
;
; SS_destDir = C:\a_dir\a_subdir\a_destination_subdir
;
; ---------------------------------------------------------------
SS_sourceDir = G:\Billeder\Nye
SS_destDir = C:\Users\kpe\Desktop\Her til
; MIRRORING
; ***************************************************************
;
; Change this to "y" for directory mirroring or to "n" for
; incremental copy without mirroring.
;
; ---------------------------------------------------------------
SS_isMirror = y
; REPLICATION CHECK GLOBAL EXCLUSIONS
; THESE ITEMS WILL NOT BE COPIED ON DESTINATION SIDE
; ***************************************************************
;
; Add source items (absolute path or relative name) to exclude
; them from the replication check. These items will not be
; created on destination side.
;
; Rules:
; ------
; [continuation section]
; [newline separated]
; [no quotes]
; [surrounded by <>]
;
; Examples:
; ---------
; SS_exReplicationXXX =
; ( LTrim
; <C:\a_source_dir\a_source_item>
; )
;
; SS_exReplicationXXXRel =
; ( LTrim
; <a_source_item>
; )
;
; ---------------------------------------------------------------
; Excluded directories (absolute path)
SS_exReplicationDirs =
( LTrim
)
; Excluded directories (relative name)
SS_exReplicationDirsRel =
( LTrim
)
; Excluded files (absolute path)
SS_exReplicationFiles =
( LTrim
)
; Excluded files (relative name)
SS_exReplicationFilesRel =
( LTrim
)
; REVERSE CHECK GLOBAL EXCLUSIONS
; THESE ITEMS WILL NOT BE DELETED ON DESTINATION SIDE
; ***************************************************************
;
; Add destination items (absolute path or relative name) to
; exclude them from the reverse check. These items will not be
; deleted on destination side.
;
; Rules:
; ------
; [continuation section]
; [newline separated]
; [no quotes]
; [surrounded by <>]
;
; Examples:
; ---------
; SS_exReverseXXX =
; ( LTrim
; <C:\a_destination_dir\a_destination_item>
; )
;
; SS_exReverseXXXRel =
; ( LTrim
; <a_destination_item>
; )
;
; ---------------------------------------------------------------
; Excluded directories (absolute path)
SS_exReverseDirs =
( LTrim
)
; Excluded directories (relative name)
SS_exReverseDirsRel =
( LTrim
)
; Excluded files (absolute path)
SS_exReverseFiles =
( LTrim
)
; Excluded files (relative name)
SS_exReverseFilesRel =
( LTrim
)
; PROGRAM INITIALIZING
; ***************************************************************
;
; Gui creation, routines start and log management.
;
; ---------------------------------------------------------------
; Gui management
Gui, 11:Add, Text, vSS_syncText Left w200, Synchronizing...
Gui, 11:Add, Button, gSS_exitLabel vSS_syncButton w50 h20 x+10, &Close
Gui, 11:-Caption +Border
Gui, 11:Show, Center Autosize, SuperSynchronizer
; Log management
VarSetCapacity(SS_logData, 10240000) ; 10MB
SS_logData = [%A_YYYY%/%A_MM%/%A_DD%]%A_Hour%:%A_Min%:%A_Sec% - REPLICATION CHECK STARTED`n******************************************************************************`n
; Core logic
SetWorkingDir, %SS_sourceDir%
SS_ReplicationCheckRecursive("*.*")
If SS_isMirror = y
{
; Log management
SS_logData = %SS_logData%`n[%A_YYYY%/%A_MM%/%A_DD%]%A_Hour%:%A_Min%:%A_Sec% - REVERSE CHECK STARTED`n******************************************************************************`n
SetWorkingDir, %SS_destDir%
SS_ReverseCheckRecursive("*.*")
}
SetWorkingDir, %A_ScriptDir%
; Log management
SS_logData = %SS_logData%`n------------------------------------------------------------------------------`n`n
FileAppend, %SS_logData%, %A_ScriptDir%\SS_log.txt
; Gui management
Gui, 11:Cancel
GuiControl, 11:, SS_syncText, DONE!
GuiControl, 11:, SS_syncButton, &Ok
GuiControl, 11:+Default, SS_syncButton
Gui, 11:Show, Center Autosize, SuperSynchronizer
Return
; Exit label
SS_exitLabel:
Gui, 11:Destroy
ExitApp
; REPLICATION CHECK ROUTINE
; ***************************************************************
;
; This function implements the replication check, where the
; source items are replicated on destination side (the function
; is recursive).
;
; ---------------------------------------------------------------
SS_ReplicationCheckRecursive(SS_aPattern)
{
Global SS_sourceDir, SS_destDir, SS_exReplicationDirs, SS_exReplicationDirsRel, SS_exReplicationFiles, SS_exReplicationFilesRel, SS_logData
Loop, %SS_aPattern%, 1
{
FileGetAttrib, SS_checkPattern, %A_LoopFileFullPath%
; It's a directory
IfInString, SS_checkPattern, D
{
; If directory isn't in exlusion lists
If (NOT InStr(SS_exReplicationDirs, "<" . A_LoopFileLongPath . ">")) AND (NOT InStr(SS_exReplicationDirsRel, "<" . A_LoopFileName . ">"))
{
; Checks if source directory exists as destination directory, if not it creates it
IfNotExist, %SS_destDir%\%A_LoopFileFullPath%
{
FileCreateDir, %SS_destDir%\%A_LoopFileFullPath%
; Log management
If ErrorLevel
{
SS_logData = %SS_logData%[%A_YYYY%/%A_MM%/%A_DD%]%A_Hour%:%A_Min%:%A_Sec% - ERROR >> Could not create directory: "%SS_destDir%\%A_LoopFileFullPath%" #`n
}
Else
{
SS_logData = %SS_logData%[%A_YYYY%/%A_MM%/%A_DD%]%A_Hour%:%A_Min%:%A_Sec% - SUCCESS >> Directory created: "%SS_destDir%\%A_LoopFileFullPath%" #`n
}
}
; Recursion into current directory
SS_ReplicationCheckRecursive(A_LoopFileFullPath . "\*.*")
}
; Directory skipped
Else
{
; Log management
SS_logData = %SS_logData%[%A_YYYY%/%A_MM%/%A_DD%]%A_Hour%:%A_Min%:%A_Sec% - SKIPPED >> Directory excluded: "%A_LoopFileLongPath%" #`n
}
}
; It's a file
Else
{
SS_copyItFlag = n
; If file isn't in exlusion lists
If (NOT InStr(SS_exReplicationFiles, "<" . A_LoopFileLongPath . ">")) AND (NOT InStr(SS_exReplicationFilesRel, "<" . A_LoopFileName . ">"))
{
; Checks if file exists in destination directory, if not sets copy flag
IfNotExist, %SS_destDir%\%A_LoopFileFullPath%
{
SS_copyItFlag = y
}
Else
{
; Checks if source file is more recent than destination file, if yes sets copy flag
FileGetTime, SS_time, %SS_destDir%\%A_LoopFileFullPath%
EnvSub, SS_time, %A_LoopFileTimeModified%, seconds
If SS_time < 0
{
SS_copyItFlag = y
}
}
}
; File skipped
Else
{
; Log management
SS_logData = %SS_logData%[%A_YYYY%/%A_MM%/%A_DD%]%A_Hour%:%A_Min%:%A_Sec% - SKIPPED >> File excluded: "%A_LoopFileLongPath%" #`n
}
; Copies file
If SS_copyItFlag = y
{
SS_destFileLongPath = %SS_destDir%\%A_LoopFileFullPath%
FileCopy, %A_LoopFileLongPath%, %SS_destFileLongPath%, 1
; Log management
If ErrorLevel
{
SS_logData = %SS_logData%[%A_YYYY%/%A_MM%/%A_DD%]%A_Hour%:%A_Min%:%A_Sec% - ERROR >> Error copying "%A_LoopFileLongPath%" to "%SS_destFileLongPath%" #`n
}
Else
{
SS_logData = %SS_logData%[%A_YYYY%/%A_MM%/%A_DD%]%A_Hour%:%A_Min%:%A_Sec% - SUCCESS >> Copied "%A_LoopFileLongPath%" to "%SS_destFileLongPath%" #`n
}
}
}
}
Return 0
}
; REPLICATION CHECK ROUTINE
; ***************************************************************
;
; This function implements the reverse check, where the
; destination side is analyzed and eventually modified to create
; a mirror copy of the source (the function is recursive).
;
; ---------------------------------------------------------------
SS_ReverseCheckRecursive(SS_aPattern)
{
Global SS_sourceDir, SS_destDir, SS_exReverseDirs, SS_exReverseDirsRel, SS_exReverseFiles, SS_exReverseFilesRel, SS_logData
Loop, %SS_aPattern%, 1
{
FileGetAttrib, SS_checkPattern, %A_LoopFileFullPath%
; It's a directory
IfInString, SS_checkPattern, D
{
; If directory doesn't exist on source side
IfNotExist, %SS_sourceDir%\%A_LoopFileFullPath%
{
; If directory isn't in exlusion lists
If (NOT InStr(SS_exReverseDirs, "<" . A_LoopFileLongPath . ">")) AND (NOT InStr(SS_exReverseDirsRel, "<" . A_LoopFileName . ">"))
{
; Backup flag (to restore the dontDeleteDirFlag if next recursion sets the flag to 0 and it was 1)
; Eg: the item is a directory that can be deleted
SS_oldFlag = SS_dontDeleteDirFlag
; Recurses and obtains a new flag
SS_dontDeleteDirFlag := SS_ReverseCheckRecursive(A_LoopFileFullPath . "\*.*")
If SS_dontDeleteDirFlag != 1
{
FileRemoveDir, %A_LoopFileFullPath%, 1
; Log management
If ErrorLevel
{
SS_logData = %SS_logData%[%A_YYYY%/%A_MM%/%A_DD%]%A_Hour%:%A_Min%:%A_Sec% - ERROR >> Could not delete directory: "%A_LoopFileLongPath%" #`n
}
Else
{
SS_logData = %SS_logData%[%A_YYYY%/%A_MM%/%A_DD%]%A_Hour%:%A_Min%:%A_Sec% - SUCCESS >> Directory removed: "%A_LoopFileLongPath%" #`n
}
; Restores flag
If SS_oldFlag = 1
{
SS_dontDeleteDirFlag = 1
}
}
; Directory skipped
Else
{
; Log management
SS_logData = %SS_logData%[%A_YYYY%/%A_MM%/%A_DD%]%A_Hour%:%A_Min%:%A_Sec% - SKIPPED >> Directory excluded because of file dependancy: "%A_LoopFileLongPath%" #`n
}
}
; Directory skipped
Else
{
SS_dontDeleteDirFlag = 1
; Log management
SS_logData = %SS_logData%[%A_YYYY%/%A_MM%/%A_DD%]%A_Hour%:%A_Min%:%A_Sec% - SKIPPED >> Directory excluded: "%A_LoopFileLongPath%" #`n
}
}
; If directory exists in source side
Else
{
SS_ReverseCheckRecursive(A_LoopFileFullPath . "\*.*")
}
}
; It's a file
Else
{
; If file doesn't exist on source side
IfNotExist, %SS_sourceDir%\%A_LoopFileFullPath%
{
; If file isn't in exclusion lists
If (NOT InStr(SS_exReverseFiles, "<" . A_LoopFileLongPath . ">")) AND (NOT InStr(SS_exReverseFilesRel, "<" . A_LoopFileName . ">"))
{
FileDelete, %A_LoopFileFullPath%
; Log management
If ErrorLevel
{
SS_logData = %SS_logData%[%A_YYYY%/%A_MM%/%A_DD%]%A_Hour%:%A_Min%:%A_Sec% - ERROR >> Could not delete "%A_LoopFileLongPath%" #`n
}
Else
{
SS_logData = %SS_logData%[%A_YYYY%/%A_MM%/%A_DD%]%A_Hour%:%A_Min%:%A_Sec% - SUCCESS >> File deleted: "%A_LoopFileLongPath%" #`n
}
}
; The file is skipped for exclusion, to keep it on destination side, sets the SS_dontDeleteDirFlag
Else
{
SS_dontDeleteDirFlag = 1
; Log management
SS_logData = %SS_logData%[%A_YYYY%/%A_MM%/%A_DD%]%A_Hour%:%A_Min%:%A_Sec% - SKIPPED >> File excluded: "%A_LoopFileLongPath%" #`n
}
}
; If file exist on source side
Else
{
; If file isn't in exclusion lists
If (NOT InStr(SS_exReverseFiles, "<" . A_LoopFileLongPath . ">")) AND (NOT InStr(SS_exReverseFilesRel, "<" . A_LoopFileName . ">"))
{
; Checks if destination file differs from source file, if yes overwrites destination file with source file
FileGetTime, SS_time, %SS_sourceDir%\%A_LoopFileFullPath%
EnvSub, SS_time, %A_LoopFileTimeModified%, seconds
If SS_time != 0
{
; Copies file from source to destination
SS_sourceFileLongPath = %SS_sourceDir%\%A_LoopFileFullPath%
FileCopy, %SS_sourceFileLongPath%, %A_LoopFileLongPath%, 1
; Log management
If ErrorLevel
{
SS_logData = %SS_logData%[%A_YYYY%/%A_MM%/%A_DD%]%A_Hour%:%A_Min%:%A_Sec% - ERROR >> Error copying "%SS_sourceFileLongPath%" to "%A_LoopFileLongPath%" #`n
}
Else
{
SS_logData = %SS_logData%[%A_YYYY%/%A_MM%/%A_DD%]%A_Hour%:%A_Min%:%A_Sec% - SUCCESS >> Copied "%SS_sourceFileLongPath%" to "%A_LoopFileLongPath%" #`n
}
}
}
}
}
}
Return SS_dontDeleteDirFlag
}