$numimage = imagecreate($imagewidth,$imageheight); imagecolorall " /> 两性色午夜视频免费播放,黄色免费在线网站,a亚洲欧美中文日韩在线v日本

一区二区久久-一区二区三区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)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 国产在视频线精品视频2021 | 国产成人综合亚洲亚洲欧美 | 国产成人精品午夜在线播放 | 中文字幕1区2区 | 亚洲毛片大全 | 精品国产欧美精品v | 国产欧美日韩综合精品一区二区三区 | 全部免费69堂在线视频 | 91精品国产91久久久久久最新 | 亚洲视频国产 | 看全色黄大色黄女视频 | 日本一道一区二区免费看 | 激情欧美一区二区三区中文字幕 | 护士freesex欧美| 91欧美精品 | 欧洲美女高清一级毛片 | 欧洲色综合精品 | 激情综合网五月激情 | 一本色道久久88 | www.色网站| 亚洲欧洲国产成人精品 | 依人成人综合网 | 日韩国产三级 | 日本高清色视频在线观看免费 | 亚洲第一区视频 | 亚洲国产www| 久久综合丝袜长腿丝袜 | 久久久久久久网 | 亚洲五月花丁香花社区 | www.亚洲精品.com | 欧美日韩中文国产一区二区三区 | 精品国产区一区二区三区在线观看 | 久久综合色区 | 美女图片在线视频精品播放 | 人人免费人人专区 | 一区二区三区成人 | 亚洲高清中文字幕一区二区三区 | 欧美精品福利视频 | 四虎最新永久免费视频 | 欧美另类xxx | 色噜噜狠狠在爱丁香 |