From 16bc87b419fcde20f48cbc50b1e4f02a690ee5dd Mon Sep 17 00:00:00 2001 From: Erik Date: Tue, 3 Sep 2024 14:53:35 -0600 Subject: [PATCH] program works but ineffective on sample data. Assembling new sample data... --- Process-Images.ps1 | 71 ++++++++++++++++++++++++++++++++++++++++++++++ README.md | 7 ++++- 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 Process-Images.ps1 diff --git a/Process-Images.ps1 b/Process-Images.ps1 new file mode 100644 index 0000000..0c4ea68 --- /dev/null +++ b/Process-Images.ps1 @@ -0,0 +1,71 @@ +# Script to find, process, and anaylze the results of processing. + +# eventually make this folder select. +$ImagePathToProcess = "C:\Users\eeckert\Downloads\Test Photos\Unmodified" +$ArchivePathBase = "\\192.168.24.15\OriginalPhotos\TestPath" +$ImageOutputPath = "C:\Users\eeckert\Downloads\Test Photos\AfterImageMagick - Pass 1" +$depth = 15 # how many folders down do we go. +$Reduction_Percentage = '25%' + +$Logging = @() + + + +if (!($ImagePathToProcess)) { + # If this path doesn't exist, then error out. Erik's a fool and has been burned by this before. + + +} else { + # do stuff! + + # get file list - image formats only + + $imagefiles = get-childitem $imagePathToProcess -Recurse -Depth $depth -Include ('*.jpg','*.png','*.bmp') + + foreach ($image in $imagefiles) { + $copyResult = $null + + # Set Paths + $SourcePath = $image.FullName + $SourceSize = $image.Length + + + $ArchivePathDest = $SourcePath.Replace($ImagePathToProcess,"") # strip sourcepath + $ArchivePath = $ArchivePathBase + $ArchivePathDest + $ArchivePath_Parent = Split-Path -Parent $ArchivePath + + New-Item -Path $ArchivePath_Parent -ItemType Directory -Force + $copyresult = Copy-Item $SourcePath $ArchivePath -Force + + if (!($copyresult)) { + $copyresult_Dest = $null + $actualDest_file = $ImageOutputPath + $SourcePath.Replace($ImagePathToProcess,"") # strip sourcepath + $actualDest_Parent = Split-Path -Parent $actualDest_file + + New-Item -Path $actualDest_Parent -ItemType Directory -Force + $copyresult_Dest = Copy-Item $SourcePath $actualDest_file -Force + + if (!($copyresult_Dest)) { + # if no error Assemble the imagemagick command line + $command = "magick" + $commandArgs = "mogrify `"$actualDest_file`" -resize $Reduction_Percentage" + + Start-Process $command -ArgumentList $commandArgs -wait + + $NewImage = get-item -path $actualDest_file + + $NewSize = $NewImage.Length + + $Logging += [PSCustomObject]@{ + FileName = $SourcePath + 'Original Size' = $SourceSize + 'New Size' = $NewSize + + } + } + + } + + } + +} \ No newline at end of file diff --git a/README.md b/README.md index 3ef38ec..916bc1e 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ # ImageResizeAndArchive -Project to update all photos on Egnyte to lower resoluiton, 72DPI photos. Original to be stored in $ArchiveLocation. \ No newline at end of file +## Project to update all photos on Egnyte to lower resoluiton, 72DPI photos. Original to be stored in $ArchiveLocation. + +$ImagePathToProcess = Location of files to process - including subfolders. +$ArchivePathBase = Location to store Archived His Res Photos + +