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

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

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

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

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)該先將顏色分配到畫布上。

(顏色標(biāo)識(shí) )= imageColorAllocate(img,r,g,b)

填充畫布

imageFill(img,x,y,顏色標(biāo)識(shí))

輸出畫布

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();
?>

運(yùn)行效果圖如下:

驗(yàn)證碼實(shí)現(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>

運(yùn)行效果圖如下:

 

<?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運(yùn)算與運(yùn)算符用法總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫(kù)操作入門教程》及《php常見數(shù)據(jù)庫(kù)操作技巧匯總

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

相關(guān)文章

最新評(píng)論

梁山县| 贵德县| 平度市| 长子县| 达孜县| 临泉县| 视频| 吉安县| 华阴市| 大连市| 葫芦岛市| 朝阳市| 平南县| 大姚县| 清水县| 平泉县| 宿松县| 通城县| 孟州市| 开化县| 嘉禾县| 吉安县| 沁源县| 玉龙| 大宁县| 沙雅县| 比如县| 聂荣县| 东安县| 平遥县| 越西县| 镇江市| 泽州县| 雷波县| 阿巴嘎旗| 绍兴县| 成安县| 台江县| 余姚市| 大宁县| 通山县|