Files
powershell-scripts/src/scripts/raw/process-images.ps1
T
2025-07-18 07:43:27 -07:00

56 lines
1.5 KiB
PowerShell

Function Get-Image
{
begin{
[System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") |Out-Null
}
process{
$fi=[System.IO.FileInfo]$_
if( $fi.Exists){
$img = [System.Drawing.Image]::FromFile($_)
$img.Clone()
$img.Dispose()
}else{
Write-Host "File not found: $_" -fore yellow
}
}
end{}
}
$dirtoprocess = "D:\resize\"
$filestoprocess = $dirtoprocess + "*.jpg"
$totalcount = ( Get-ChildItem $dirtoprocess | Measure-Object ).Count
$processed = 0
dir $filestoprocess -Recurse | % {
$processed++
Write-Progress -Activity 'Processing' -Status ('Fetching Image ' + $processed + ' of ' + $totalcount) -PercentComplete ($processed / $totalcount * 100)
$image = $_ | Get-Image
$width = $image.Width
$height = $image.Height
$image.Dispose()
if(786 -gt $width -and 786 -gt $height)
{
write-host ("Removing Item..." + $_.FullName)
Remove-Item $_
}
if(1280 -lt $width -or 1280 -lt $height)
{
write-host ("Shrinking Item..." + $_.FullName)
$cmdline = "E:AppData\XYplorer\Tools\ImageMagick\mogrify.exe -resize 1280x1280 " + $_.FullName
invoke-expression -command $cmdline
}
if ($processed % 1000 -eq 0)
{
$leavenow = Read-Host "Process 1000 more records?"
if ($leavenow -eq 'Y' -or $leavenow -eq 'y')
{
write-host "Doing more stuff now..."
}
else
{
write-host "Bye fucker..."
break
}
}
}