PHP如何实现等比压缩图片大小-创新互联

这篇文章主要介绍了PHP如何实现等比压缩图片大小,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。

创新互联公司主营清镇网站建设的网络公司,主营网站建设方案,重庆APP开发公司,清镇h5微信平台小程序开发搭建,清镇网站营销推广欢迎清镇等地区企业咨询

具体代码如下所示:

 $maxwidth) && ($maxheight && $pic_height > $maxheight))
{
if($maxwidth && $pic_width>$maxwidth)
{
$widthratio = $maxwidth/$pic_width;
$resizewidth_tag = true;
}
if($maxheight && $pic_height>$maxheight)
{
$heightratio = $maxheight/$pic_height;
$resizeheight_tag = true;
}
if($resizewidth_tag && $resizeheight_tag)
{
if($widthratio<$heightratio)
$ratio = $widthratio;
else
$ratio = $heightratio;
}
if($resizewidth_tag && !$resizeheight_tag)
$ratio = $widthratio;
if($resizeheight_tag && !$resizewidth_tag)
$ratio = $heightratio;
$newwidth = $pic_width * $ratio;
$newheight = $pic_height * $ratio;
if(function_exists("imagecopyresampled"))
{
$newim = imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($newim,$im,,,,,$newwidth,$newheight,$pic_width,$pic_height);
}
else
{
$newim = imagecreate($newwidth,$newheight);
imagecopyresized($newim,$im,,,,,$newwidth,$newheight,$pic_width,$pic_height);
}
$name = $name.$filetype;
imagejpeg($newim,$name);
imagedestroy($newim);
}
else
{
$name = $name.$filetype;
imagejpeg($im,$name);
} 
}

感谢你能够认真阅读完这篇文章,希望小编分享的“PHP如何实现等比压缩图片大小”这篇文章对大家有帮助,同时也希望大家多多支持创新互联网站建设公司,,关注创新互联行业资讯频道,更多相关知识等着你来学习!


本文名称:PHP如何实现等比压缩图片大小-创新互联
文章地址:http://csruizhi.cn/article/cohoee.html

其他资讯

Copyright © 2007-2024 成都优众联杰科技有限公司 All Rights Reserved 蜀ICP备2024116266号
友情链接: 网站建设推广 高端网站设计 成都网站建设 营销型网站建设 手机网站制作设计 成都网站设计 成都品牌网站设计 品牌网站建设 手机网站制作 网站制作 自适应网站设计 成都网站建设 网站建设费用 成都模版网站建设 成都网站设计 手机网站设计 手机网站制作 高端网站设计 专业网站建设 成都网站制作公司 企业手机网站建设 重庆手机网站建设