<?php

header('Content-Type: image/png');
$im = imagecreatetruecolor( 200 , 50 );
//生成图片长宽 // Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);//背景色 imagefilledrectangle($im, 0, 0, 200, 49, $white); // The text to draw
$rand = rand( 1 ,2 ) ;
$one = rand(1,9);
$two = rand(1,9);
if( $rand == 1 ){ $result = $one + $two;
$text = "$one+$two=?"; }else{
if( $one < $two ){
list( $two , $one ) = [ $one , $two ];
}
$result = $one - $two;
$text = "$one-$two=?";
} session_start();
$_SESSION['code'] = $result;
// Replace font
$font = './Arvo-Regular.ttf'; //imageline( $im , 0 , rand( 1,49 ) , 199 , 30 , $grey );
//干扰线
// Add the text
$i = 0;
$len = strlen( $text );
while( $i < $len ){
if( is_numeric( $text[$i] ) ){
imagettftext($im, 20, rand(-45,45), 20 * ($i+1) , 30, $black, $font, $text[$i]);
}else{
imagettftext($im, 20, 0 , 20 * ($i+1) , 30, $black, $font, $text[$i]);
}
//echo $text[$i];
$i ++;
}
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);

  如果生成图片为空,请检测字体引入路径是否有问题。

利用PHP 简单实现加减法验证码的更多相关文章

  1. 利用 canvas 破解 某拖动验证码

    利用 canvas 破解 某拖动验证码 http://my.oschina.net/u/237940/blog/337194

  2. 一般处理程序生成简单的图片验证码并通过html验证用户输入的验证码是否正确

    一般处理程序生成简单的图片验证码并通过html验证用户输入的验证码是否正确       最近没事研究了下验证码的的动态生成及通过cookie实现HTML页面对用户输入的验证码的校验,简要如下: 1.写 ...

  3. django 利用pillow 进行简单的设置验证码(python)

    1.导入模块 并定义一个验证状态 from PIL import Image, ImageDraw, ImageFont from django.utils.six import BytesIO de ...

  4. 利用cookies跳过登陆验证码

    前言在爬取某些网页时,登陆界面时经常遇到的一个坎,而现在大多数的网站在登陆时都会要求用户填写验证码.当然,我们可以设计一套机器学习的算法去破解验证码,然而,验证码的形式多种多样,稍微变一下(有些甚至是 ...

  5. Unity利用SMSSDK实现短信验证码(附代码)

    最近一直在研究如何给app更多实用性的功能,在app进行登录或者注册时,为了方便用户更加快捷的完成登录功能,所以就决定采用短信验证码的方式进行验证登录.在学习的过程中,先使用了Mob的短信服务进行短信 ...

  6. CentOS6.4 安装OpenResty和Redis 并在Nginx中利用lua简单读取Redis数据

    1.下载OpenResty和Redis OpenResty下载地址:wget http://openresty.org/download/ngx_openresty-1.4.3.6.tar.gz Re ...

  7. 基于Python使用SVM识别简单的字符验证码的完整代码开源分享

    关键字:Python,SVM,字符验证码,机器学习,验证码识别 1   概述 基于Python使用SVM识别简单的验证字符串的完整代码开源分享. 因为目前有了更厉害的新技术来解决这类问题了,但是本文作 ...

  8. 用Java制作一个简单的图片验证码

    //Java实现简单验证码功能 package project; import java.awt.Color; import java.awt.Font;import java.awt.Graphic ...

  9. go 利用orm简单实现接口分布式锁

    在开发中有些敏感接口,例如用户余额提现接口,需要考虑在并发情况下接口是否会发生问题.如果用户将自己的多条提现请求同时发送到服务器,代码能否扛得住呢?一旦没做锁,那么就真的会给用户多次提现,给公司带来损 ...

随机推荐

  1. 页面布局整理(基于scss)

    页面开发步骤: 1.全局reset.设置基础背景色.设置基础字体样式 2.全局布局页面结构,meta 标签引入 3.按钮等相同的样式,用scss提前写好一份公用,渐变等 border-radius b ...

  2. Awake & Start

    [Awake & Start] MonoBehaviour.Awake() Awake is used to initialize any variables or game state be ...

  3. char(10)、varchar(10)、nchar(10)、nvarchar(10)的区别

    CHAR CHAR是定长的,当输入的字符小于10时,会在后面补空值,如果长度大于10,则会截取超出的字符 CHAR字段上的索引效率级高 VARCHAR 存储边长数据,但存储效率没有CHAR高 从空间上 ...

  4. 252. Meeting Rooms 区间会议室

    [抄题]: Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],.. ...

  5. 409. Longest Palindrome 最长对称串

    [抄题]: Given a string which consists of lowercase or uppercase letters, find the length of the longes ...

  6. Apache apxs命令

    一.简介 apxs是一个为Apache HTTP服务器编译和安装扩展模块的工具,用于编译一个或多个源程序或目标代码文件为动态共享对象,使之可以用由mod_so提供的LoadModule指令在运行时加载 ...

  7. 数字图像处理实验(12):PROJECT 05-03,Periodic Noise Reduction Using a Notch Filter 标签: 图像处理MATLAB 2017-0

    实验要求: Objective: To understand the principle of the notch filter and its periodic noise reducing abi ...

  8. linux操作小技巧

    巧妙利用别称 alias,让工作更有效率 在我的个人目录下/home/zdwu,打开.bashrc文件进行修改: 将  ll='ls -alF' 改为 ll='ls -ahlF',是的观察的结果显示更 ...

  9. CLR VIA C# 泛型的协变和逆变

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  10. C# 世界坐标 页面坐标 PageUnit PageScale

    PageScale:  获取或设置此 Graphics 的世界单位和页单位之间的比例.PageUnit:  获取或设置用于此 Graphics 中的页坐标的度量单位. 话不多说,上代码: privat ...