PHP 實現(xiàn)等比壓縮圖片尺寸和大小實例代碼
更新時間:2016年10月08日 14:41:36 投稿:lqh
這篇文章主要介紹了PHP 實現(xiàn)等比壓縮圖片尺寸和大小實例代碼的相關資料,需要的朋友可以參考下
廢話不多說了,直接給大家貼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); } }
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
相關文章
js+php實現(xiàn)靜態(tài)頁面實時調用用戶登陸狀態(tài)的方法
這篇文章主要介紹了js+php實現(xiàn)靜態(tài)頁面實時調用用戶登陸狀態(tài)的方法,采用在靜態(tài)頁面中使用js調用php頁面從而實現(xiàn)用戶登錄狀態(tài)的實時調用功能,需要的朋友可以參考下2015-01-01php+MySql實現(xiàn)登錄系統(tǒng)與輸出瀏覽者信息功能
這篇文章主要介紹了php+MySql實現(xiàn)登錄系統(tǒng)與輸出瀏覽者信息功能 的相關資料,需要的朋友可以參考下2016-07-07php adodb連接帶密碼access數(shù)據(jù)庫實例,測試成功
最近前臺有個開票系統(tǒng)需要改進導致需要用PHP去連接那個系統(tǒng)的 數(shù)據(jù)庫,ACCESS的帶密碼的。寫了個簡單的實例,記錄下。2008-05-05