// 压缩图片
function compressImage($sourcePath, $quality = 75)
{
    // 创建图像实例
    $image = \think\Image::open($sourcePath);

    // 压缩图片并覆盖原图
    $image->save($sourcePath, null, $quality);  // 保存到原路径,覆盖原图

    // 清除文件状态缓存
    clearstatcache();

    // 获取压缩后的文件大小
    $compressedSize = filesize($sourcePath);

    return $compressedSize;  // 返回压缩后的文件大小
}

function yasuo($sourcePath)
{
    $sourcePath = ROOT_PATH . DS . 'public' . DS . $sourcePath;
    try {
        $filesizeinfo = compressImage($sourcePath, 30); // 设置压缩质量,范围 1-100
        return $filesizeinfo;
    } catch (\Exception $e) {
        echo "Error: " . $e->getMessage();
    }
}

$filesizeinfo = compressImage($sourcePath, 30); // 设置压缩质量,范围 1-100


点赞(0)

评论列表 共有 0 条评论

暂无评论
立即
投稿
发表
评论
返回
顶部
{__SCRIPT__}