您的位置 首页 php

php中将png、jpg压缩成WebP格式

png与jpg图片必须是Photoshop导出web原图,且不能用第三软件或web压缩,否则会出错。

<?php

$dir = __DIR__ . ‘/seomuyun.com/’;

imgtype($dir);

function imgtype($dir)

{

$dir = rtrim($dir, ‘/’) . ‘/’;

$hd = opendir($dir);

while ($hf = readdir($hd)) {

if ($hf == ‘.’ || $hf == ‘..’) {

continue;

}

turnType($dir.$hf);

}

}

function turnType($file)

{

if (is_file($file)) {

$ext = pathinfo($file, PATHINFO_EXTENSION);;

if ($ext == ‘jpeg’ || $ext == ‘jpg’ || $ext == ‘png’) {

$newpic = rtrim($file, $ext) . ‘webp’;

if ($ext == ‘jpg’) {

$ext = ‘jpeg’;

}

$funName = ‘imagecreatefrom’ . $ext;

$hImg = $funName($file);

imagewebp($hImg, $newpic);

imagedestroy($hImg);

}

}

}

文章来源:智云一二三科技

文章标题:php中将png、jpg压缩成WebP格式

文章地址:https://www.zhihuclub.com/78170.shtml

关于作者: 智云科技

热门文章

网站地图