mirror of
https://github.com/nsnail/NetAdmin.git
synced 2025-06-20 18:58:16 +08:00
build: 📦 整理构建相关的工程文件 (#64)
This commit is contained in:
65
scripts/image.optimize.csx
Normal file
65
scripts/image.optimize.csx
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
for %%i in (*.png) do pngquant %%i --force --output %%i --skip-if-larger
|
||||
for %%i in (*.jpg) do jpegtran -copy none -optimize -perfect %%i %%i
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
var files = Directory
|
||||
.EnumerateFiles(
|
||||
"../",
|
||||
"*.png",
|
||||
new EnumerationOptions
|
||||
{
|
||||
RecurseSubdirectories = true,
|
||||
AttributesToSkip = FileAttributes.ReparsePoint,
|
||||
IgnoreInaccessible = true
|
||||
}
|
||||
)
|
||||
.ToArray();
|
||||
|
||||
Parallel.ForEach(
|
||||
files,
|
||||
file =>
|
||||
{
|
||||
var startInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = "pngquant",
|
||||
Arguments = $"\"{file}\" --force --output \"{file}\" --skip-if-larger"
|
||||
};
|
||||
using var p = Process.Start(startInfo);
|
||||
p.WaitForExit();
|
||||
Console.WriteLine($"{file}: {p.ExitCode}");
|
||||
}
|
||||
);
|
||||
|
||||
files = new[] { "*.jpg", "*.jpeg" }
|
||||
.SelectMany(
|
||||
x =>
|
||||
Directory.EnumerateFiles(
|
||||
"../",
|
||||
x,
|
||||
new EnumerationOptions
|
||||
{
|
||||
RecurseSubdirectories = true,
|
||||
AttributesToSkip = FileAttributes.ReparsePoint,
|
||||
IgnoreInaccessible = true
|
||||
}
|
||||
)
|
||||
)
|
||||
.ToArray();
|
||||
|
||||
Parallel.ForEach(
|
||||
files,
|
||||
file =>
|
||||
{
|
||||
var startInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = "jpegtran",
|
||||
Arguments = $"-copy none -optimize -perfect \"{file}\" \"{file}\""
|
||||
};
|
||||
using var p = Process.Start(startInfo);
|
||||
p.WaitForExit();
|
||||
Console.WriteLine($"{file}: {p.ExitCode}");
|
||||
}
|
||||
);
|
Reference in New Issue
Block a user