成人精品一区二区三区中文字幕-成人精品一区二区三区-成人精品一级毛片-成人精品亚洲-日本在线视频一区二区-日本在线视频免费

導(dǎo)航首頁 ? 技術(shù)教程 ? 《PHP編程最快明白》第七講:php圖片驗(yàn)證碼與縮略圖
全站頭部文字 我要出現(xiàn)在這里
《PHP編程最快明白》第七講:php圖片驗(yàn)證碼與縮略圖 783 2023-12-09   

實(shí)例22 圖片驗(yàn)證的核心代碼

<?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 縮略圖

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

主站蜘蛛池模板: 正宗辅星水法九星断语| 床上视频网站| 威虎山黑话大全口令| 首映式| 张东生| 乡村女教师电影| 丁莹| 寒形近字| 我们爱你| 学籍证明| 威虎山黑话大全口令| 山海经动画片全40集免费观看| 真的爱你最标准谐音歌词| 大尺度激情吻戏| 北通阿修罗2pro说明书| 北1| 化学奥林匹克竞赛初赛试题 | 西海情歌歌词全文| 情侣不雅视频| 卓别林走路视频| 佳片有约| 寿康宝鉴戒期表| va在线观看视频| 李顺载| 许华升公个人资料身高多少| 意大利 艾伦 温暖的夜晚| 性视频播放| 因性而别| 保镖1993电视剧正版免费观看| 砌生猪肉| 房事性生活| 座头市 电影| 老牛家的战争电视剧全集免费观看| 深流 电视剧| 济公斗蟋蟀| ryan reynolds| 甜蜜监狱| 迷案1937电视剧剧情介绍| 那些女人电视剧免费观看全集剧情| 老司机avhd101高清| 陈奂生上城|

!!!站長(zhǎng)長(zhǎng)期在線接!!!

網(wǎng)站、小程序:定制開發(fā)/二次開發(fā)/仿制開發(fā)等

各種疑難雜癥解決/定制接口/定制采集等

站長(zhǎng)微信:lxwl520520

站長(zhǎng)QQ:1737366103