$numimage = imagecreate($imagewidth,$imageheight); imagecolorall " /> 久久精品综合视频,国产午夜三级一区二区三,国产一区在线视频

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

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

實例22 圖片驗證的核心代碼
復制代碼 代碼如下:
<?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函數,用到的時候大家再網上搜索吧。你要產生隨機數,那有mt_rand函數;你還要用到session保存這個隨機數;如果需要轉成utf-8,需要iconv函數。

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

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

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

主站蜘蛛池模板: 布莱德·德尔森| 人民的名义电视剧免费版| 外出韩版| 爱之梦钢琴谱| 暖春| 百字明咒标准读诵慢念| 朱宝意| 山东卫视体育频道| 牵牛花的生长变化记录| 免费观看淫www视频| a型血和b型血生的孩子是什么血型| 日老妇| 长谷川清| 邓稼先教学设计一等奖优秀教案| 韩国成人综艺| 繁华在线观看| 湖南卫视直播| 相声剧本(适合学生)| 汤唯完整版| 胸曝光| 韩剧上流社会| 隐藏的真相| 抖音浏览器| 电视剧狂飙演员名单| 以下关于宏病毒说法正确的是| 刑道荣| 章子怡和郭富城的吻戏| 女生宿舍1电影| 我们的故事 电视剧| 企鹅头像| 爱秀直播| 电影《武状元苏乞儿》| 补锌之王的食物| 大槻响作品| 23号牛乃唐第二季免费观看| 2024微信头像图片| 拥日之月| lovelivesuperstar| 千羽千翔公棚| 姐妹兄弟演员表| 私密按摩|