feat: implement plant health scanning functionality with backend integration and UI support
This commit is contained in:
49
SplitImage.ps1
Normal file
49
SplitImage.ps1
Normal file
@@ -0,0 +1,49 @@
|
||||
param (
|
||||
[string]$ImagePath,
|
||||
[string]$OutputDir,
|
||||
[string]$Prefix
|
||||
)
|
||||
|
||||
Add-Type -AssemblyName System.Drawing
|
||||
|
||||
$img = [System.Drawing.Image]::FromFile($ImagePath)
|
||||
$w = $img.Width
|
||||
$h = $img.Height
|
||||
|
||||
$targetWidth = $w
|
||||
$targetHeight = [math]::Floor($w / 3.0)
|
||||
|
||||
$left = 0
|
||||
$top = 0
|
||||
|
||||
if ($targetHeight -gt $h) {
|
||||
$targetHeight = $h
|
||||
$targetWidth = $h * 3
|
||||
$left = [math]::Floor(($w - $targetWidth) / 2.0)
|
||||
} else {
|
||||
$top = [math]::Floor(($h - $targetHeight) / 2.0)
|
||||
}
|
||||
|
||||
[int]$sqSize = [math]::Floor($targetWidth / 3.0)
|
||||
|
||||
[int]$leftInt = $left
|
||||
[int]$topInt = $top
|
||||
|
||||
for ($i = 0; $i -lt 3; $i++) {
|
||||
$bmp = New-Object System.Drawing.Bitmap -ArgumentList $sqSize, $sqSize
|
||||
$g = [System.Drawing.Graphics]::FromImage($bmp)
|
||||
|
||||
[int]$rx = $leftInt + ($i * $sqSize)
|
||||
$srcRect = New-Object System.Drawing.Rectangle -ArgumentList $rx, $topInt, $sqSize, $sqSize
|
||||
$destRect = New-Object System.Drawing.Rectangle -ArgumentList 0, 0, $sqSize, $sqSize
|
||||
|
||||
$g.DrawImage($img, $destRect, $srcRect, [System.Drawing.GraphicsUnit]::Pixel)
|
||||
$g.Dispose()
|
||||
|
||||
$outFile = Join-Path $OutputDir ("{0}_part{1}.png" -f $Prefix, ($i + 1))
|
||||
$bmp.Save($outFile, [System.Drawing.Imaging.ImageFormat]::Png)
|
||||
$bmp.Dispose()
|
||||
}
|
||||
|
||||
$img.Dispose()
|
||||
Write-Output "Successfully split the image into 3 pieces."
|
||||
Reference in New Issue
Block a user