最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

php實現(xiàn)圖片按比例截取的方法

 更新時間:2017年02月06日 11:41:13   作者:風(fēng)起從容  
這篇文章主要介紹了php實現(xiàn)圖片按比例截取的方法,涉及php針對圖形的讀取、運算及生成相關(guān)操作技巧,具有一定參考借鑒價值,需要的朋友可以參考下

本文實例講述了php實現(xiàn)圖片按比例截取的方法。分享給大家供大家參考,具體如下:

filename = 'img/test.jpg';
$all_type = array(
"jpg"  => array("create"=>"ImageCreateFromjpeg", "output"=>"imagejpeg"  , "exn"=>".jpg"),
"gif"  => array("create"=>"ImageCreateFromGIF" , "output"=>"imagegif"  , "exn"=>".gif"),
"jpeg"  => array("create"=>"ImageCreateFromjpeg", "output"=>"imagejpeg"  , "exn"=>".jpg"),
"png"  => array("create"=>"imagecreatefrompng" , "output"=>"imagepng"  , "exn"=>".png"),
"wbmp"  => array("create"=>"imagecreatefromwbmp", "output"=>"image2wbmp" , "exn"=>".wbmp")
);
$imgtype = getimagesize($filename);
$width = $imgtype[0];
$height = $imgtype[1];
$type = str_replace('image/','',$imgtype['mime']);
$func_create = $all_type[$type]['create'];
$func_output = $all_type[$type]['output'];
$x = $y =0;
if(($width * 100)>($height * 120))
{
$newwidth = ceil($height * 120/100);
$newheight = $height;
$x = ($width-$newwidth)/2;
}
elseif(($width * 100)<($height * 120))
{
$newheight = ceil($width * 100/120);
$newwidth = $width;
$y = ($height-$newheight)/2;
}
else
{
$newheight = $height;
$newwidth = $width; 
}
// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = $func_create($filename);
// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $newwidth, $newheight);
// Output
$func_output($thumb,'a.jpeg');

PS:這里再為大家推薦幾款比較實用的圖片處理工具供大家參考使用:

在線圖片轉(zhuǎn)換BASE64工具:
http://tools.jb51.net/transcoding/img2base64

ICO圖標在線生成工具:
http://tools.jb51.net/aideddesign/ico_img

在線Email郵箱圖標制作工具:
http://tools.jb51.net/email/emaillogo

在線圖片格式轉(zhuǎn)換(jpg/bmp/gif/png)工具:
http://tools.jb51.net/aideddesign/picext

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP圖形與圖片操作技巧匯總》、《PHP基本語法入門教程》、《PHP運算與運算符用法總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計入門教程》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總

希望本文所述對大家PHP程序設(shè)計有所幫助。

相關(guān)文章

最新評論

浦县| 田林县| 五莲县| 孟津县| 鹤山市| 繁峙县| 遂川县| 明溪县| 高青县| 博客| 绩溪县| 海丰县| 宁南县| 紫阳县| 龙泉市| 内乡县| 蒲城县| 葵青区| 阿勒泰市| 大渡口区| 都兰县| 汝阳县| 射阳县| 桦川县| 淅川县| 红原县| 闽侯县| 铅山县| 敦化市| 山西省| 子长县| 蚌埠市| 观塘区| 嘉鱼县| 房产| 呼图壁县| 洛扎县| 襄樊市| 伊吾县| 郸城县| 台南市|