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

首頁 > 語言 > PHP > 正文

PHP 實現等比壓縮圖片尺寸和大小實例代碼

2024-05-04 23:50:43
字體:
來源:轉載
供稿:網友

廢話不多說了,直接給大家貼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);}}

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!


注:相關教程知識閱讀請移步到PHP教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 夹江县| 南宫市| 大余县| 龙海市| 合山市| 尚志市| 乾安县| 武强县| 呼伦贝尔市| 裕民县| 东至县| 洱源县| 中阳县| 宝山区| 改则县| 台东市| 赞皇县| 西贡区| 宕昌县| 天柱县| 攀枝花市| 洪雅县| 武乡县| 丰都县| 安仁县| 湖州市| 收藏| 景德镇市| 孟连| 曲麻莱县| 云霄县| 老河口市| 泽库县| 苗栗县| 株洲县| 多伦县| 岑巩县| 手游| 突泉县| 靖宇县| 大竹县|