File tree 1 file changed +10
-8
lines changed
1 file changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -117,19 +117,21 @@ $imageList = Get-ChildItem |
117
117
# Assume the order is image, mask, image, mask
118
118
$resizedMasks = [System.Collections.Generic.List [string ]]::new()
119
119
for ($i = 0 ; $i -lt $imageList.Count ; $i = $i + 2 ) {
120
- # Read image for reference
120
+ # Read files
121
121
$image = New-Object - TypeName System.Drawing.Bitmap - ArgumentList $imageList [$i ]
122
122
$mask = New-Object - TypeName System.Drawing.Bitmap - ArgumentList $imageList [$i + 1 ]
123
123
# Rescale and save mask based on the image's dimensions
124
124
if ($image.Width -ne $mask.Width -or $image.Height -ne $mask.Height ) {
125
- $resizedMasks.Add ($imageList [$i + 1 ].Name )
125
+ $resizedMasks.Add ($imageList [$i + 1 ])
126
126
Resize-Image - Width $image.Width - Height $image.Height - ImagePath $imageList [$i + 1 ]
127
127
}
128
+ # Release resources
129
+ $image.Dispose ()
130
+ $NewImage.Dispose ()
128
131
}
129
132
130
- # Move old masks into an `old_masks` directory as clean-up
131
- $null = New-Item - ItemType Directory - Name ../ old_masks
132
- $resizedMasks |
133
- ForEach-Object { $_ -replace ' _resized(?=\.png$)' } |
134
- Move-Item - Destination ../ old_masks
135
-
133
+ # Move old masks into an `old_masks` directory as clean-up
134
+ if (-not (Test-Path ../ old- masks)) {
135
+ $null = New-Item - ItemType Directory - Name ../ old_masks
136
+ }
137
+ $resizedMasks | ForEach-Object { Move-Item - Path $_ - Destination ../ old_masks }
You can’t perform that action at this time.
0 commit comments