$numimage = imagecreate($imagewidth,$imageheight); imagecolorall " /> 国产精品福利电影,在线免费观看国产,成人黄色在线看

四虎精品视频-四虎精品成人免费网站-四虎黄色网-四虎国产视频-国产免费91-国产蜜臀97一区二区三区

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

實(shí)例22 圖片驗(yàn)證的核心代碼
復(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);
?>

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

實(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']);//上傳的臨時(shí)文件名
$image->resizeToWidth(80);設(shè)置寬度
$image->save($newfile);
?>

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

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

主站蜘蛛池模板: 护花使者歌词| 菲律宾电影甜蜜宝贝| 绿野仙踪电影| 性感瑜伽| 抖音网站入口| 香港之夜在线观看免费版香港电影| 1988田螺姑娘| 黄秋生的电影| 裸体杂技dvd| 混的人头像| 女明星曝光| 复仇者联盟4在线完整版观看| 十一码复式22块钱中奖对照表| 黄视频在线播放| 视力图| 日本电影家庭教师| 安全员c证考试免费题库| 机械师3| 演觉法师| 血色恶魔| 科室对分级护理落实情况检查记录| 葫撸娃| 毕业生在线观看| 金鸳鸯| 冬日行动电影免费观看| 格伦鲍威尔| 极品白嫩嫩模酒店援交土豪av| 布袋头| 女生被艹| xiuren秀人网免费| 回到黑暗 电影| 自制化妆豆豆本| 张晓婷| 名剑风流 电视剧| 伦理电影在线看| 巫山历险记| 曹查理电影大全免费观看| 诱惑的艺术| 恩齐| 年轻阿姨的性教育| 俺去也电影网|