PHP建站技术分享-从入门到精通_各类知识收集PHP建站技术分享-从入门到精通_各类知识收集PHP建站技术分享-从入门到精通_各类知识收集

QQ:420220301 微信/手机:150-3210-7690
当前位置:首页 > 工作总结

PHP应用:PHP 实现等比压缩图片尺寸和大小实例代码

管理员 2025-02-25
工作总结
8

《PHP应用:PHP  实现等比压缩图片尺寸和大小实例代码》要点:
本文介绍了PHP应用:PHP  实现等比压缩图片尺寸和大小实例代码,希望对您有用。如果有疑问,可以联系我们。
 

废话不多说了,直接给大家贴php等比压缩图片大小的相关代码了,具体代码如下所示:
PHP教程

<?php$im = imagecreatefromjpeg('D:phpplace.jpeg');resizeImage($im,,,'xinde','.jpg');function resizeImage($im,$maxwidth,$maxheight,$name,$filetype){$pic_width = imagesx($im);$pic_height = imagesy($im);echo "start-----------------" ;if(($maxwidth && $pic_width > $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);}}



希望以上内容对你有所帮助!如果还有其他问题,请随时提问。 各类知识收集 拥有多年CMS企业建站经验,对 iCMS, LeCMS, ClassCMS, Fastadmin, PbootCMS, PHPCMS, 易优CMS, YzmCMS, 讯睿CMS, 极致CMS, Wordpress, HkCMS, YznCMS, WellCMS, ThinkCMF, 等各类cms的相互转化,程序开发,网站制作,bug修复,程序杀毒,插件定制都可以提供最佳解决方案。

相关推荐

扫码关注

qrcode

QQ交谈

回顶部