国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > PHP > 正文

基于PHP實(shí)現(xiàn)等比壓縮圖片大小

2024-05-04 23:43:35
字體:
供稿:網(wǎng)友
通過本段代碼給大家介紹基于php實(shí)現(xiàn)等比壓縮圖片大小的相關(guān)知識(shí),代碼簡單易懂,對(duì)php壓縮圖片相關(guān)知識(shí)感興趣的朋友參考下吧
 

廢話不多說了,直接給大家貼php等比壓縮圖片大小的相關(guān)代碼了,具體代碼如下所示:

<?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);} } 

以上代碼內(nèi)容是小編給大家介紹的基于PHP實(shí)現(xiàn)等比壓縮圖片大小的相關(guān)內(nèi)容,代碼簡單易懂,哪里寫的不好,歡迎各位大俠多多提出寶貴意見,小編非常樂意。



注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到PHP教程頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 安庆市| 德格县| 韶关市| 崇州市| 疏勒县| 五台县| 石狮市| 山东省| 清远市| 常德市| 安顺市| 建始县| 遂平县| 邳州市| 星座| 吴旗县| 石屏县| 井研县| 新沂市| 鲁山县| 丰镇市| 确山县| 克东县| 大埔县| 且末县| 天祝| 霍林郭勒市| 新巴尔虎右旗| 临漳县| 福州市| 射阳县| 西乌珠穆沁旗| 吉水县| 确山县| 溧水县| 仲巴县| 樟树市| 弥勒县| 敖汉旗| 攀枝花市| 江北区|