[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
回复 3# wh123wh123

RemoveICCfromJPG.ps1
  1. Add-Type -AssemblyName System.Drawing
  2. $cp = New-Object CodeDom.Compiler.CompilerParameters
  3. $cp.ReferencedAssemblies.Add([Reflection.Assembly]::GetAssembly([Drawing.Image]).Location) >$null
  4. $cp.CompilerOptions ='/unsafe'
  5. Add-Type -CompilerParameters $cp -TypeDefinition @"
  6. using System;
  7. using System.Drawing;
  8. using System.Drawing.Imaging;
  9. using System.IO;
  10. public class ImageProcessor
  11. {
  12.     public static void RemoveICCProfile(string imagePath)
  13.     {
  14.         string tempPath = Path.GetTempFileName();
  15.         using (Image image = Image.FromFile(imagePath))
  16.         {
  17.             if (image.PropertyItems.Length > 0)
  18.             {
  19.                 foreach (PropertyItem propertyItem in image.PropertyItems)
  20.                 {
  21.                     if (propertyItem.Id == 0x8773)
  22.                     {
  23.                         image.RemovePropertyItem(propertyItem.Id);
  24.                     }
  25.                 }
  26.             }
  27.             image.Save(tempPath, ImageFormat.Jpeg);
  28.         }
  29.         File.Delete(imagePath);
  30.         File.Move(tempPath, imagePath);
  31.     }
  32. }
  33. "@
  34. dir *.jpg | ForEach-Object {
  35.     [ImageProcessor]::RemoveICCProfile($_.FullName)
  36. }
复制代码

TOP

回复 9# terse


    ISE才可以

TOP

回复 17# wh123wh123


    whiteCoverJPG.ps1
  1. Add-Type -AssemblyName System.Drawing
  2. function Cover-Image {
  3.     param(
  4.         [string]$ImagePath,
  5.         [int]$TopCover,
  6.         [int]$BottomCover
  7.     )
  8.     $originalImage = [System.Drawing.Image]::FromFile($ImagePath)
  9.     $originalHeight = $originalImage.Height
  10.     $originalWidth = $originalImage.Width
  11.     $graphics = [System.Drawing.Graphics]::FromImage($originalImage)
  12.     $whiteBrush = New-Object System.Drawing.SolidBrush([System.Drawing.Color]::White)
  13.     $graphics.FillRectangle($whiteBrush, 0, 0, $originalWidth, $TopCover)
  14.     $graphics.FillRectangle($whiteBrush, 0, $originalHeight - $BottomCover, $originalWidth, $BottomCover)
  15.     $coveredImagePath = [System.IO.Path]::ChangeExtension($ImagePath, "covered.jpg")
  16.     $originalImage.Save($coveredImagePath, [System.Drawing.Imaging.ImageFormat]::Jpeg)
  17. }
  18. # 白色覆盖顶部100像素,底部150像素
  19. $topCover = 100
  20. $bottomCover = 150
  21. dir *.jpg | ForEach-Object {
  22.     Cover-Image -ImagePath $_.FullName -TopCover $topCover -BottomCover $bottomCover
  23.     }
复制代码

TOP

回复 35# wh123wh123

removeRedWatermark.ps1
  1. Add-Type -AssemblyName System.Drawing
  2. function removeRedWatermark-Image {
  3.     param([string]$imagePath)
  4.     $image = [System.Drawing.Bitmap]::FromFile($imagePath)
  5.     $rect = New-Object System.Drawing.Rectangle(0, 0, $image.Width, $image.Height)
  6.     $bitmapData = $image.LockBits($rect, [System.Drawing.Imaging.ImageLockMode]::ReadWrite, $image.PixelFormat)
  7.     $ptr = $bitmapData.Scan0
  8.     $bytes = $bitmapData.Stride * $image.Height
  9.     $rgbValues = New-Object byte[] $bytes
  10.     [System.Runtime.InteropServices.Marshal]::Copy($ptr, $rgbValues, 0, $bytes)
  11.     for ($i = 0; $i -lt $rgbValues.Length; $i += 3) {
  12.         $b = $rgbValues[$i]
  13.         $g = $rgbValues[$i + 1]
  14.         $r = $rgbValues[$i + 2]
  15.         if ($r -gt $g -and $r -gt $b) {
  16.             $total = $r + $g + $b
  17.             if ($total -gt 400) {
  18.                 $rgbValues[$i] = 255
  19.                 $rgbValues[$i + 1] = 255
  20.                 $rgbValues[$i + 2] = 255
  21.             } else {
  22.                 $rgbValues[$i] = 0
  23.                 $rgbValues[$i + 1] = 0
  24.                 $rgbValues[$i + 2] = 0
  25.             }
  26.         }
  27.     }
  28.     [System.Runtime.InteropServices.Marshal]::Copy($rgbValues, 0, $ptr, $bytes)
  29.     $image.UnlockBits($bitmapData)
  30.     $newPath = [System.IO.Path]::GetDirectoryName($imagePath) + "\processed_" + [System.IO.Path]::GetFileName($imagePath)
  31.     $image.Save($newPath)
  32.     $image.Dispose()
  33. }
  34. $(dir *.jpg).foreach{
  35.     Write-Host "processing: $($_.Name)"
  36.     removeRedWatermark-Image $_.FullName
  37. }
复制代码

TOP

返回列表