File tree Expand file tree Collapse file tree 1 file changed +10
-8
lines changed Expand file tree Collapse file tree 1 file changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -117,19 +117,21 @@ $imageList = Get-ChildItem |
117117# Assume the order is image, mask, image, mask
118118$resizedMasks = [System.Collections.Generic.List [string ]]::new()
119119for ($i = 0 ; $i -lt $imageList.Count ; $i = $i + 2 ) {
120- # Read image for reference
120+ # Read files
121121 $image = New-Object - TypeName System.Drawing.Bitmap - ArgumentList $imageList [$i ]
122122 $mask = New-Object - TypeName System.Drawing.Bitmap - ArgumentList $imageList [$i + 1 ]
123123 # Rescale and save mask based on the image's dimensions
124124 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 ])
126126 Resize-Image - Width $image.Width - Height $image.Height - ImagePath $imageList [$i + 1 ]
127127 }
128+ # Release resources
129+ $image.Dispose ()
130+ $NewImage.Dispose ()
128131}
129132
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