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

PHP基于GD庫的圖像處理方法小結(jié)

 更新時間:2016年09月27日 11:13:33   作者:ligbee  
這篇文章主要介紹了PHP基于GD庫的圖像處理方法,結(jié)合實例形式總結(jié)分析了php操作GD庫實現(xiàn)圖形繪制功能的相關(guān)技巧與注意事項,需要的朋友可以參考下

本文實例講述了PHP基于GD庫的圖像處理方法。分享給大家供大家參考,具體如下:

gd圖像處理技術(shù)

extension=php_gd2.dll

創(chuàng)建畫布

畫布,一種資源型數(shù)據(jù),可操作的圖像資源

創(chuàng)建畫布(新建)

imageCreate(width,height) //創(chuàng)建基于調(diào)色板的畫布

imageCreateTrueColor(width,height) //創(chuàng)建真彩色的畫布

基于圖片創(chuàng)建畫布(打開)

imageCreateFromJPEG( url)
imageCreateFromPNG(url)
imageCreateFromGIF(url)

操作畫布

分配顏色:如果需要在畫布上使用某種顏色,應(yīng)該先將顏色分配到畫布上。

(顏色標識 )= imageColorAllocate(img,r,g,b)

填充畫布

imageFill(img,x,y,顏色標識)

輸出畫布

1. 輸出到圖片文件

2. 直接輸出,需要告知瀏覽器輸出為圖片信息(header("Content-type:image/png;")

imagePNG(img[,url])
imageJPEG()
imageGIF()

銷毀畫布資源

imageDestroy(img)

<?php
header('content-type:image/png');
$img = imagecreate(300,300);
$color = imagecolorallocate($img,223,22,44);
imagefill($img,3,3,$color);
imagepng($img);
imagedestroy();
?>

運行效果圖如下:

驗證碼實現(xiàn)

<?php
  header('content-type:image/png');
  $code = '123456789abcdefghijklmnpqrstuvwxvz';
  $length = strlen($code);
  $print = '';
  for($i=0; $i<4; $i++){
    $print.=$code[mt_rand(0,$length-1)];
  }
//  echo $print;
  $img = imagecreatefrompng('./str.png');
  $color = mt_rand(0,1)==1?imagecolorallocate($img,0,0,0):imagecolorallocate($img,255,255,255);
  //圖片大小
  $img_width = imagesx($img);
  $img_height = imagesy($img);
  //字體大小
  $font = 5;
  $font_width = imagefontwidth($font);
  $font_height = imagefontheight($font);
  $fin_w = ($img_width-$font_width*4)/2;
  $fin_h = ($img_height-$font_height)/2;
  imagestring($img,$font,$fin_w,$fin_h,$print,$color);
  imagepng($img);
  imagedestroy($img);
?>
<image src="gd_string.php" onclick="this.src='gd_string.php?ra='+Math.random()"></image>

運行效果圖如下:

 

<?php
session_start();
$im=imagecreatetruecolor(80,30);
$str="";
for ($i=0;$i<4;$i++){
  $str.=dechex(rand(0,15));
}
$_SESSION['code']=$str;
$white=imagecolorallocate($im,255,255,255);
imagestring($im,rand(2,5),rand(0,70),rand(0,10),$str,$white);
//imagettftext($im,rand(0,5),rand(0,180),rand(0,100),rand(0,10),$white,"simhei.ttf",$str);
for($i=0;$i<20;$i++){
$color=imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imageline($im,rand(0,90),rand(0,20),rand(0,100),rand(0,100),$color);
}
header("content-type:image/png");
imagepng($im);
imagedestroy($im);
?>

注意:圖片輸出前后不能有額外輸出

更多關(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)文章

最新評論

青铜峡市| 湛江市| 诸暨市| 阳城县| 大渡口区| 清徐县| 平阴县| 饶河县| 安丘市| 庄河市| 青州市| 家居| 齐齐哈尔市| 龙陵县| 泾阳县| 陇南市| 得荣县| 德江县| 茂名市| 石景山区| 康定县| 岳西县| 巴林左旗| 双辽市| 乌恰县| 垦利县| 榆林市| 丰顺县| 温州市| 沙湾县| 上思县| 朝阳县| 措美县| 舟山市| 关岭| 筠连县| 含山县| 道孚县| 乌鲁木齐市| 巨鹿县| 田阳县|