Skip to content

Commit c0c77c6

Browse files
committed
Update mask-rescaler.ps1
1 parent b4412f6 commit c0c77c6

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

mask-rescaler.ps1

+10-8
Original file line numberDiff line numberDiff 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()
119119
for ($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 }

0 commit comments

Comments
 (0)