回复 3# wh123wh123
RemoveICCfromJPG.ps1- Add-Type -AssemblyName System.Drawing
- $cp = New-Object CodeDom.Compiler.CompilerParameters
- $cp.ReferencedAssemblies.Add([Reflection.Assembly]::GetAssembly([Drawing.Image]).Location) >$null
- $cp.CompilerOptions ='/unsafe'
- Add-Type -CompilerParameters $cp -TypeDefinition @"
- using System;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.IO;
-
- public class ImageProcessor
- {
- public static void RemoveICCProfile(string imagePath)
- {
- string tempPath = Path.GetTempFileName();
-
- using (Image image = Image.FromFile(imagePath))
- {
- if (image.PropertyItems.Length > 0)
- {
- foreach (PropertyItem propertyItem in image.PropertyItems)
- {
- if (propertyItem.Id == 0x8773)
- {
- image.RemovePropertyItem(propertyItem.Id);
- }
- }
- }
-
- image.Save(tempPath, ImageFormat.Jpeg);
- }
-
- File.Delete(imagePath);
- File.Move(tempPath, imagePath);
- }
- }
- "@
-
- dir *.jpg | ForEach-Object {
- [ImageProcessor]::RemoveICCProfile($_.FullName)
- }
复制代码
|