pdo文字水印类,验证码类,缩略图类,logo类
文字水印类
<?php
/**
* webrx.cn qq:7031633
* @author webrx
* @copyright copyright (c) 2003-2014 webrx Inc. (http://www.webrx.cn)
* @version 2014-9-7 webrx@126.com
*/
class Image {
private $f;
private $i;
private $path;
public function __construct($i = '') {
$this->f = dirname ( __FILE__ ) . '/f.ttf';
if (empty ( $i )) {
} else {
$this->i = imagecreatefromjpeg ( $i );
$this->path = $i;
}
}
public function check($len = 4) {
session_start ();
header ( 'content-type:image/png' );
$fs = [
'/a.ttf',
'/b.ttf',
'/f.ttf'
];
$font = dirname ( __FILE__ ) . $fs [mt_rand ( 0, 1 )];
$w = 35 * $len;
$h = 50;
$this->i = imagecreatetruecolor ( $w, $h );
$c = imagecolorallocatealpha ( $this->i, 0, 0, 0, 127 );
// imagecolortransparent($i,$c);
// imagefill($i,0,0,$c);
imagefilledrectangle ( $this->i, 0, 0, $w, $h, $this->gc ( $this->i, 'ffffff', mt_rand ( 0, 2 ) ) );
$sss = '';
for($j = 0; $j < $len; $j ++) {
$st = $this->gs ( 1 );
$sss .= $st;
imagettftext ( $this->i, mt_rand ( 15, 25 ), mt_rand ( - 30, 30 ), $j * 35 + 10, mt_rand ( 28, 38 ), $this->gc ( $this->i ), $font, $st );
}
$_SESSION ['code'] = $sss;
imagesetthickness ( $this->i, mt_rand ( 2, 8 ) );
for($j = 0; $j < mt_rand ( 5, 10 ); $j ++) {
imagefilledarc ( $this->i, mt_rand ( 0, $w ), mt_rand ( 0, $h ), mt_rand ( 0, $w ), mt_rand ( 0, $h ), mt_rand ( 0, 360 ), mt_rand ( 0, 360 ), $this->gc ( $this->i, 'rand', mt_rand ( 100, 120 ) ), IMG_ARC_NOFILL );
}
for($j = 0; $j < 10; $j ++) {
imagettftext ( $this->i, mt_rand ( 10, 15 ), mt_rand ( - 5, 5 ), mt_rand ( 0, $w ), mt_rand ( 0, $h ), $this->gc ( $this->i, 'rand', mt_rand ( 100, 120 ) ), $font, $this->gs ( 1 ) );
}
imagepng ( $this->i );
}
public function gs($n = 4) {
$s = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$t = '';
for($i = 0; $i < $n; $i ++) {
$t .= substr ( $s, mt_rand ( 0, strlen ( $s ) - 1 ), 1 );
}
return $t;
}
public function setImg($i) {
$this->i = imagecreatefromjpeg ( $i );
$this->path = $i;
}
public function text($s = 30, $t = '版权所有', $c = 'rand', $a = 0, $p = 5, $f = true, $fn = 't_') {
$ii = getimagesize ( $this->path );
if ($ii [2] == 2) {
if ($ii [0] > 300) {
$pos = imagettfbbox ( $s, 0, $this->f, $t );
$pad = 30;
switch ($p) {
case 1 : // 左上角
$x = 0 - $pos [0] + $pad;
$y = 0 - $pos [7] + $pad;
break;
case 2 : // 上边 水平中央
$x = ($ii [0] - $pos [2]) / 2;
$y = 0 - $pos [7] + $pad;
break;
case 3 :
$x = $ii [0] - $pos [2] - $pad;
$y = 0 - $pos [7] + $pad;
break;
case 4 :
$x = 0 - $pos [0] + $pad;
$y = ($ii [1] - $pos [6]) / 2;
break;
case 5 :
$x = ($ii [0] - $pos [2]) / 2;
$y = ($ii [1] - $pos [6]) / 2;
break;
case 6 :
$x = $ii [0] - $pos [2] - $pad;
$y = ($ii [1] - $pos [6]) / 2;
break;
case 7 :
$x = 0 - $pos [0] + $pad;
$y = $ii [1] - $pos [6] - $pad;
break;
case 8 :
$x = ($ii [0] - $pos [2]) / 2;
$y = $ii [1] - $pos [6] - $pad;
break;
case 9 :
$x = $ii [0] - $pos [2] - $pad;
$y = $ii [1] - $pos [6] - $pad;
break;
}
imagettftext ( $this->i, $s, 0, $x, $y, $this->gc ( $this->i, $c, $a ), $this->f, $t );
if ($f) {
imagejpeg ( $this->i, $this->path );
} else {
$path = dirname ( $this->path ) . '/';
$name = $fn . substr ( $this->path, strrpos ( $this->path, '/' ) + 1 );
imagejpeg ( $this->i, $path . $name );
}
}
}
}
public function logo($p = 5, $f = true, $fn = 'logo_') {
$ii = getimagesize ( $this->path );
if ($ii [2] == 2) {
if ($ii [0] > 300) {
$w = $ii [0];
$h = $ii [1];
// 水银图标 logo.png 格式
$logo = dirname ( __FILE__ ) . '/logo.png';
$li = imagecreatefrompng ( $logo );
$liw = imagesx ( $li );
$lih = imagesy ( $li );
$x = ($w - $liw) / 2;
$y = ($h - $lih) / 2;
$pad = 35;
switch ($p) {
case 1 :
$x = 0 + $pad;
$y = 0 + $pad;
break;
case 2 :
$y = 0 + $pad;
break;
case 3 :
$x = $w - $liw - $pad;
$y = 0 + $pad;
break;
case 4 :
$x = 0 + $pad;
break;
case 6 :
$x = $w - $liw - $pad;
break;
case 7 :
$x = 0 + $pad;
$y = $h - $lih - $pad;
break;
case 8 :
$y = $h - $lih - $pad;
break;
case 9 :
$x = $w - $liw - $pad;
$y = $h - $lih - $pad;
break;
}
imagecopy ( $this->i, $li, $x, $y, 0, 0, $liw, $lih );
if ($f) {
imagejpeg ( $this->i, $this->path );
} else {
$path = dirname ( $this->path ) . '/';
$name = $fn . substr ( $this->path, strrpos ( $this->path, '/' ) + 1 );
imagejpeg ( $this->i, $path . $name );
}
imagedestroy ( $li );
}
}
}
public function thumb($f = false, $w = 220, $h = 0, $fn = 's_') {
$ii = getimagesize ( $this->path );
if ($ii [2] == 2) {
if ($ii [0] > $w) {
$sw = $ii [0];
$sh = $ii [1];
$h = $h == 0 ? $w / $sw * $sh : $h;
$dst = imagecreatetruecolor ( $w, $h );
imagecopyresampled ( $dst, $this->i, 0, 0, 0, 0, $w, $h, $sw, $sh );
if ($f) {
imagejpeg ( $dst, $this->path );
} else {
$path = dirname ( $this->path ) . '/';
$name = $fn . substr ( $this->path, strrpos ( $this->path, '/' ) + 1 );
imagejpeg ( $dst, $path . $name );
}
imagedestroy ( $dst );
}
}
}
public function gc($i, $c = 'rand', $a = 0) {
$color = '';
switch ($c) {
case 'white' :
$color = imagecolorallocatealpha ( $i, 255, 255, 255, $a );
break;
case 'black' :
$color = imagecolorallocatealpha ( $i, 0, 0, 0, $a );
break;
case 'red' :
$color = imagecolorallocatealpha ( $i, 255, 0, 0, $a );
break;
case 'green' :
$color = imagecolorallocatealpha ( $i, 0, 255, 0, $a );
break;
case 'rand' :
$color = imagecolorallocatealpha ( $i, mt_rand ( 0, 255 ), mt_rand ( 0, 255 ), mt_rand ( 0, 255 ), $a );
break;
default :
$cc = str_split ( $c, 2 );
$color = imagecolorallocatealpha ( $i, hexdec ( $cc [0] ), hexdec ( $cc [1] ), hexdec ( $cc [2] ), $a );
break;
}
return $color;
}
public function __destruct() {
if (isset ( $this->i )) {
imagedestroy ( $this->i );
}
}
}
<?php
include 'inc/Image.class.php';
$i=new Image('c:/a.jpg');
$i->text();
<?php
include 'inc/Image.class.php';
$i=new Image('c:/a.jpg');
$i->text();
$i->setImg('c:/b.jpg');
$i->text(50);
$i->setImg('c:/c.jpg');
$i->text(100);
<?php
include 'inc/Image.class.php';
$i=new Image();
$i->check(4);
<?php
include 'inc/Image.class.php';
$i=new Image();
$i->setImg('c:/d.jpg');
$i->thumb(false,200);
<?php
include 'inc/Image.class.php';
$i=new Image();
$i->setImg('c:/d.jpg');
$i->logo();
<?php
include 'inc/Image.class.php';
$i=new Image();
$i->setImg('c:/d.jpg');
$i->logo(5,false); //5 表示位置,false表示新建一张图片
pdo文字水印类,验证码类,缩略图类,logo类的更多相关文章
- php使用GD库实现图片水印和缩略图——封装成类
学完了如何使用GD库来实现对图片的各种处理,那么我们可以发现,不管哪种方法,都有相似之处,如果我们把这些相似的地方和不相似的地方都封装成类,这样就可以提升代码的速度,而且节省了很多时间,废话不多说,来 ...
- 本图片处理类功能非常之强大可以实现几乎所有WEB开发中对图像的处理功能都集成了,包括有缩放图像、切割图像、图像类型转换、彩色转黑白、文字水印、图片水印等功能
import java.awt.AlphaComposite; import java.awt.Color; import java.awt.Font; import java.awt.Graphic ...
- java常用开发工具类之 图片水印,文字水印,缩放,补白工具类
import java.awt.AlphaComposite; import java.awt.Color; import java.awt.Font; import java.awt.Graphic ...
- PHP的生成图片或文字水印的类
ImageWatermark.php <?php /*********************************************************** 类名:ImageWat ...
- php 图片操作类,支持生成缩略图,添加水印,上传缩略图
<?php class Image { //类开始 public $originimage = ""; //源图片文件地址 public $image ...
- * 类描写叙述:字符串工具类 类名称:String_U
/****************************************** * 类描写叙述:字符串工具类 类名称:String_U * ************************** ...
- DRF框架(五)——context传参,二次封装Response类,两个视图基类(APIView/GenericAPIView),视图扩展类(mixins),子类视图(工具视图),视图集(viewsets),工具视图集
复习 1.整体修改与局部修改 # 序列化get (给前端传递参数) #查询 ser_obj = ModelSerializer(model_obj) #只传递一个参数,默认是instance的参数,查 ...
- C# 生成图片验证码 图片缩略图 水印
using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D ...
- 22.编写一个类A,该类创建的对象可以调用方法showA输出小写的英文字母表。然后再编写一个A类的子类B,子类B创建的对象不仅可以调用方法showA输出小写的英文字母表,而且可以调用子类新增的方法showB输出大写的英文字母表。最后编写主类C,在主类的main方法 中测试类A与类B。
22.编写一个类A,该类创建的对象可以调用方法showA输出小写的英文字母表.然后再编写一个A类的子类B,子类B创建的对象不仅可以调用方法showA输出小写的英文字母表,而且可以调用子类新增的方法sh ...
随机推荐
- 算法(第4版)-1.3.1 API
总结:本小节介绍了泛型.自动装箱.迭代.Bag.Queue.Stack以及一个栈用例的经典例子--算术表达式求值. 重点: 1. 集合类的抽象数据类型的一个关键特性是我们应该可以用它们储存任意类型的数 ...
- Eclipse设置JSP页面的默认编码
1.一般新建jsp页面是默认编码为ISO-8895-1编码.但是,实际应用中为避免编码问题带来的麻烦,我们一般需要设置默认编码为UTF-8. 2.设置 Eclipse->Window->P ...
- Gym 100960G (set+树状数组)
Problem Youngling Tournament 题目大意 给一个序列a[i],每次操作可以更改一个数,每次询问 将序列排序后有多少个数a[i]>=sum[i-1]. n<=10^ ...
- 十分钟了解分布式计算:Petuum
Petuum是一个机器学习专用分布式计算框架,本文介绍其架构,并基于文章 More Effective Distributed ML via a Stale Synchronous Parallel ...
- [读书笔记]OSGI-灵活的类加载器架构
以下内容来自周志明的<深入理解Java虚拟机>. 学习JEE规范,去看JBoss源码:学习类加载器,就去看OSGI源码. OSGI,即Open Service Gateway Initia ...
- s查找父节点
查找所有的父节点,包括本身,不包括就<>id with tbs as(select * from TB_HomeBase where ID=223 union all select a.* ...
- Fortran学习心得
编译调试: 服务器上所用的编译器可以编译.F90的文件,同时,经过测试已经知道有两款编译器:gfortran和ifort. 另外,查看编译器的bash命令是:gfortran -v. 编程算法思想与C ...
- SQL Server使用convert对datetime日期数据进行获取
来源:http://database.51cto.com/art/201007/211883.htm 备注:本文的语法讲解确实是比较乱,似乎格式不太严谨.参考时还是以实例验证为准比较好 以下的文章主要 ...
- ASP.NET 下拉列表绑定枚举类型值,不用再新建一个枚举表
public partial class Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArg ...
- python 之post、get与cookie实战
项目名称:登陆考勤管理系统爬取个人考勤信息并写入excel表格 编写目的: 公司经常要统计员工的考勤信息,而员工每次都要登陆考勤系统,再复制相关信息出来,贴到EXCEL,再转给统计人员,统计人员再挨个 ...