网上找了图片压缩方法,只是缩小了尺寸,现在能设置质量(Quality)达到压缩的效果,设置的尺寸适合移动平台。
function GetEncoder([Drawing.Imaging.ImageFormat]$format)
{
$codecs = [System.Drawing.Imaging.ImageCodecInfo]::GetImageDecoders()
foreach ($codec in $codecs)
{
if ($codec.FormatID -eq $format.Guid)
{
return $codec;
}
}
return $null;
}
function Imgformat([io.fileinfo]$imagefile,$newimgname){
$img=[System.Drawing.Image]::FromFile($imagefile.fullname)
# 按百分比重新计算图片大小
[double]$width = 0;
[double]$height = 0;
$widthconfig=720
$heightconfig=1440
if ($img.Width -gt $img.Height -and $img.Width -gt $widthconfig)
{
$width = [System.Math]::Ceiling([Convert]::ToDouble($img.Width / ($img.Width / $widthconfig)));
$height = [System.Math]::Ceiling([Convert]::ToDouble($img.Height / ($img.Width /$widthconfig)));
}
elseif ($img.Width -lt $img.Height -a