PHP 圖像尺寸調(diào)整代碼
更新時間:2010年05月26日 00:02:21 作者:
創(chuàng)建圖像縮略圖需要許多時間,此代碼將有助于了解縮略圖的邏輯。
復(fù)制代碼 代碼如下:
/**********************
*@filename - path to the image
*@tmpname - temporary path to thumbnail
*@xmax - max width
*@ymax - max height
*/
function resize_image($filename, $tmpname, $xmax, $ymax)
{
$ext = explode(".", $filename);
$ext = $ext[count($ext)-1];
if($ext == "jpg" || $ext == "jpeg")
$im = imagecreatefromjpeg($tmpname);
elseif($ext == "png")
$im = imagecreatefrompng($tmpname);
elseif($ext == "gif")
$im = imagecreatefromgif($tmpname);
$x = imagesx($im);
$y = imagesy($im);
if($x <= $xmax && $y <= $ymax)
return $im;
if($x >= $y) {
$newx = $xmax;
$newy = $newx * $y / $x;
}
else {
$newy = $ymax;
$newx = $x / $y * $newy;
}
$im2 = imagecreatetruecolor($newx, $newy);
imagecopyresized($im2, $im, 0, 0, 0, 0, floor($newx), floor($newy), $x, $y);
return $im2;
}
這里是摘自腳本之家之前發(fā)布的文章。更多的技巧可以參考。
收集的二十一個實用便利的PHP函數(shù)代碼
相關(guān)文章
PHP配合微信小程序?qū)崿F(xiàn)獲取手機號碼詳解
這篇文章主要為大家詳細介紹了PHP如何配合微信小程序?qū)崿F(xiàn)獲取手機號碼功能,文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學習一下2022-08-08PHP基于curl模擬post提交json數(shù)據(jù)示例
這篇文章主要介紹了PHP基于curl模擬post提交json數(shù)據(jù)操作,結(jié)合實例形式分析了php使用curl實現(xiàn)post方式提交json數(shù)據(jù)相關(guān)操作步驟與注意事項,代碼簡單實用,需要的朋友可以參考下2018-06-06php 從指定數(shù)字中獲取隨機組合的簡單方法(推薦)
下面小編就為大家?guī)硪黄猵hp 從指定數(shù)字中獲取隨機組合的簡單方法(推薦)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-04-04