php中文汉字验证码生成程序
发布:smiling 来源: PHP粉丝网 添加日期:2014-08-19 14:08:42 浏览: 评论:0
本文章提供一款php中文汉字验证码生成程序,如果在图片片生成汉字,需要font文件和imagettftext函数,用到的时候大家再网上搜索吧,你要产生随机数,那有mt_rand函数,你还要用到session保存这个随机数,如果需要转成utf-8,需要iconv函数.
php中文汉字验证码生成程序实例代码如下:
- <?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;
- }
- }
- //开源代码phpfensi.com
- $newfile = upload_dir."/icons/".md5($_session['user']->email).".jpg";//上传文件保存的目录
- $image = new simpleimage();
- $image->load($_files['icons']['tmp_name']);//上传的临时文件名
- $image->resizetowidth(80);设置宽度
- $image->save($newfile);
- ?>
Tags: php中文汉字 php验证码
- 上一篇:php生成验证码详细教程
- 下一篇:php 给图片增加背景平铺水印代码
相关文章
- ·php 中文汉字验证码生成程序(2014-08-19)
- ·php两款生成图形验证码的代码(2014-08-19)
- ·php生成验证码类代码(2014-08-19)
- ·php生成验证码实现代码(2014-08-19)
- ·php生成验证码详细教程(2014-08-19)
- ·php图片验证码代码(2014-08-19)
- ·php生成图片与验证码图片生成原理(2014-08-19)
- ·php生成图形验证码(2014-08-19)
- ·php 验证码生成程序,可自动判断php gd库(2014-08-19)
- ·php 验证码图片程序(2014-08-20)
- ·php 生成验证码程序(2014-08-20)
- ·php 简单的验证码生成实例(2014-08-22)
- ·php验证码生成程序代码(2014-08-22)
- ·推荐一款php验证码程序(2014-08-23)
- ·php验证码生成与应用实例(2014-08-23)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)