powershell 缩小并压缩图片

本文介绍了如何使用PowerShell脚本实现图片的尺寸调整和质量压缩,特别适用于优化移动平台的显示效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 网上找了图片压缩方法,只是缩小了尺寸,现在能设置质量(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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值