Import
This commit is contained in:
1 parent
72452dc05d
commit
e455935474
12 files changed
+776
-2
No files matched your search
@@ -0,0 +1,56 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user