$numimage = imagecreate($imagewidth,$imageheight); imagecolorall " /> 波多野衣结在线精品二区,小明永久免费,成人免费www在线高清观看

一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

《PHP編程最快明白》第七講:php圖片驗證碼與縮略圖

實例22 圖片驗證的核心代碼
復(fù)制代碼 代碼如下:
<?php
//header("content-type:image/png");
$num ='1234';
$imagewidth=60;
$imageheight=18;

$numimage = imagecreate($imagewidth,$imageheight);
imagecolorallocate($numimage,240,240,240);
for($i=0;$i<strlen($num);$i++){
$x = mt_rand(1,8)+$imagewidth*$i/4;
$y = mt_rand(1,$imageheight/4);
$color=imagecolorallocate($numimage,mt_rand(0,150),mt_rand(0,150),mt_rand(0,150));
imagestring($numimage,5,$x,$y,$num[$i],$color);
}

for($i=0;$i<200;$i++){
$randcolor=imagecolorallocate($numimage,rand(200,255),rand(200,255),rand(200,255));
imagesetpixel($numimage,rand()%70,rand()%20,$randcolor);
}
imagepng($numimage);
imagedestroy($numimage);
?>

這個是輸出4個驗證碼的例子,對于漢字,需要font文件和imagettftext函數(shù),用到的時候大家再網(wǎng)上搜索吧。你要產(chǎn)生隨機數(shù),那有mt_rand函數(shù);你還要用到session保存這個隨機數(shù);如果需要轉(zhuǎn)成utf-8,需要iconv函數(shù)。

實例23 縮略圖
復(fù)制代碼 代碼如下:
<?php
class SimpleImage {
var $image;
var $image_type;
function load($filename) {
$image_info = getimagesize($filename);
$this->image_type = $image_info[2];
if( $this->image_type == IMAGETYPE_JPEG ) {
$this->image = imagecreatefromjpeg($filename);
} elseif( $this->image_type == IMAGETYPE_GIF ) {
$this->image = imagecreatefromgif($filename);
} elseif( $this->image_type == IMAGETYPE_PNG ) {
$this->image = imagecreatefrompng($filename);
}
}
function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) {
if( $image_type == IMAGETYPE_JPEG ) {
imagejpeg($this->image,$filename,$compression);
} elseif( $image_type == IMAGETYPE_GIF ) {
imagegif($this->image,$filename);
} elseif( $image_type == IMAGETYPE_PNG ) {
imagepng($this->image,$filename);
}
if( $permissions != null) {
chmod($filename,$permissions);
}
}
function output($image_type=IMAGETYPE_JPEG) {
if( $image_type == IMAGETYPE_JPEG ) {
imagejpeg($this->image);
} elseif( $image_type == IMAGETYPE_GIF ) {
imagegif($this->image);
} elseif( $image_type == IMAGETYPE_PNG ) {
imagepng($this->image);
}
}
function getWidth() {
return imagesx($this->image);
}
function getHeight() {
return imagesy($this->image);
}
function resizeToHeight($height) {
$ratio = $height / $this->getHeight();
$width = $this->getWidth() * $ratio;
$this->resize($width,$height);
}
function resizeToWidth($width) {
$ratio = $width / $this->getWidth();
$height = $this->getheight() * $ratio;
$this->resize($width,$height);
}
function scale($scale) {
$width = $this->getWidth() * $scale/100;
$height = $this->getheight() * $scale/100;
$this->resize($width,$height);
}
function resize($width,$height) {
$new_image = imagecreatetruecolor($width, $height);
imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
$this->image = $new_image;
}
}

$newfile = UPLOAD_DIR."/icons/".md5($_SESSION['USER']->email).".jpg";//上傳文件保存的目錄
$image = new SimpleImage();
$image->load($_FILES['icons']['tmp_name']);//上傳的臨時文件名
$image->resizeToWidth(80);設(shè)置寬度
$image->save($newfile);
?>

php技術(shù)《PHP編程最快明白》第七講:php圖片驗證碼與縮略圖,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 国产精品视频九九九 | 小视频国产| 久久婷婷影院 | 国产综合自拍 | 亚洲夂夂婷婷色拍ww47 | 欧美xxxx色视频在线观看免费 | 久久国产成人福利播放 | 国产精品亚洲欧美一级久久精品 | 国产一区国产二区国产三区 | 好吊妞在线 | 91嫩草国产线免费观看 | 亚洲欧洲国产经精品香蕉网 | 国产成人精品一区二三区2022 | 天天爽天天操 | 国产色婷婷免费视频 | 日韩三级中文 | 成人午夜视频在线观 | 亚洲免费网站 | 精品免费久久久久久久 | 玖玖青草 | 亚洲激情欧美 | 四虎免费永久在线播放 | 中国美女牲交一级毛片 | 成人久久精品 | 伊人网在线免费观看 | 黄网在线免费看 | 美女被男人桶到嗷嗷叫爽网站 | 91福利国产在线观看 | 在线国产一区二区三区 | 国产区成人精品视频 | 久草中文在线 | 天天偷窥网 | 亚洲欧美日韩国产精品第不页 | 亚洲激情黄色 | 国产亚洲精品美女久久久久久2021 | 狠狠网 | 日本久久道一区二区三区 | 欧美日韩成人午夜免费 | 久久久久亚洲精品影视 | 欧美成人v视频免费看 | 九九久久亚洲综合久久久 |