回复 17# wh123wh123
whiteCoverJPG.ps1- Add-Type -AssemblyName System.Drawing
- function Cover-Image {
- param(
- [string]$ImagePath,
- [int]$TopCover,
- [int]$BottomCover
- )
- $originalImage = [System.Drawing.Image]::FromFile($ImagePath)
- $originalHeight = $originalImage.Height
- $originalWidth = $originalImage.Width
- $graphics = [System.Drawing.Graphics]::FromImage($originalImage)
- $whiteBrush = New-Object System.Drawing.SolidBrush([System.Drawing.Color]::White)
- $graphics.FillRectangle($whiteBrush, 0, 0, $originalWidth, $TopCover)
- $graphics.FillRectangle($whiteBrush, 0, $originalHeight - $BottomCover, $originalWidth, $BottomCover)
-
- $coveredImagePath = [System.IO.Path]::ChangeExtension($ImagePath, "covered.jpg")
- $originalImage.Save($coveredImagePath, [System.Drawing.Imaging.ImageFormat]::Jpeg)
- }
-
- # 白色覆盖顶部100像素,底部150像素
- $topCover = 100
- $bottomCover = 150
-
- dir *.jpg | ForEach-Object {
- Cover-Image -ImagePath $_.FullName -TopCover $topCover -BottomCover $bottomCover
- }
复制代码
|