<?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. log4net 入门教程

    1.下载dll 下载地址:http://mirror.reverse.net/pub/apache/logging/log4net/binaries/ github:https://github.co ...

  2. 06-Location详解之精准匹配

    之前nginx不是编译过吗?现在重新make install一下. 刚刚这个是我们新安装的.原始版的nginx,配置文件比较少,便于我们做调试. 试试精准匹配的概念. 匹配的是/.优先匹配这个最精准的 ...

  3. Linux查看内存,负载状态

    Linux查看内存,负载状态 查看内存使用情况  www.ahlinux.com cat /proc/meminfo MemTotal:       16332644 kB MemFree:     ...

  4. hdu1269 Tarjan强连通分量 模板(转)

    #include<stdio.h> #include<iostream> #include<vector> using namespace std; ; vecto ...

  5. ios7适配--隐藏status bar

    //viewDidload if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) { // iOS 7 ...

  6. Build fat static library (device + simulator) using Xcode and SDK 4+

    155down votefavorite 185 It appears that we can - theoretically - build a single static library that ...

  7. Graph cut使用方法

    下载:http://www.wisdom.weizmann.ac.il/~bagon/matlab.html 1. 运行compile_gc.m 2.运行gc_example.m(必须同目录吗?!) ...

  8. python DDT读取excel测试数据

    转自:http://www.cnblogs.com/nuonuozhou/p/8645129.html ddt   结合单元测试一起用 ddt(data.driven.test):数据驱动测试 由外部 ...

  9. [Lua快速了解一下]Lua的语法

    -注释 -- 两个减号是行注释 -块注释 --[[ 这是块注释 这是块注释 --]] -变量 Lua的数字只有double型,64bits, Lua的字符串string支持双引号或者单引号 以下例子会 ...

  10. poj2299 Ultra-QuickSort(线段树求逆序对)

    Description In this problem, you have to analyze a particular sorting algorithm. The algorithm proce ...