PHP:GD库 图片水印处理
文章来源:http://www.cnblogs.com/hello-tl/p/7592974.html
<?php
/**
* 处理图片类
* 1.添加文字水印
* 2.添加图片水印
* 3.压缩图片
*/
class TL_Image{
private $image;//内存中的图片
private $info;//图片的基本信息
/**
* 打开一张图片,读取到内存
* @param [type] $src [description] 图片路径
*/
public function __construct($src){
$info = getimagesize($src);
$this->info = array(
'width' => $info[0],
'height' => $info[1],
'type' => image_type_to_extension($info['2'],false),
'mime' => $info['mime'],
);
$fun = "imagecreatefrom{$this->info['type']}";
$this->image = $fun($src);
}
/**
* 操作图片(压缩)
* @param [type] $width [description] 宽
* @param [type] $height [description] 高
* @return [type] [description]
*/
public function thumb($width,$height){
$image_thumb = imagecreatetruecolor($width,$height);
imagecopyresampled($image_thumb, $this->image, 0, 0, 0, 0, $width, $height, $this->info['width'], $this->info['height']);
imagedestroy($this->image);
$this->image = $image_thumb;
}
/**
* 操作图片(添加文字水印)
* [fontMark description]
* @param [type] $content [description] 设置文字
* @param [type] $font_url [description] 字体文件路径
* @param [type] $size [description] 字体大小
* @param [type] $color [description] 字体颜色 []
* @param [type] $local [description] 位置 []
* @param [type] $angle [description] 旋转
* @return [type] [description]
*/
public function fontMark($content,$font_url,$size,$color,$local,$angle){
$col = imagecolorallocatealpha($this->image,$color[0],$color[1],$color[2],$color[3]);
imagettftext($this->image, $size, $angle, $local['x'], $local['y'], $col, $font_url, $content);
}
/**
* 操作图片(添加图片水印)
* @param [type] $source [description] 水印图片路径
* @param [type] $local [description] 位置 []
* @param [type] $alpha [description] 透明
* @return [type] [description]
*/
public function imageMark($source,$local,$alpha){
$info2 = getimagesize($source);
$type2 = image_type_to_extension($info2[2],false);
$fun2 = "imagecreatefrom{$type2}";
$water = $fun2($source);
imagecopymerge($this->image, $water, $local['x'], $local['y'], 0, 0, $info2[0], $info2[1], $alpha);
imagedestroy($water);
}
/**
* 浏览器输出图片
*/
public function show(){
header("Content-Type:" . $this->info['mime']);
$funs = "image{$this->info['type']}";
$funs($this->image);
}
/**
* 保存图片
* @param [type] $newname [description] 保存之后的名字
* @return [type] [description]
*/
public function save($srcs){
$funs = "image{$this->info['type']}";
$funs($this->image,$srcs);
//move_uploaded_file($this->image, $srcs);
}
/**
* 销毁图片
*/
public function __destruct(){
imagedestroy($this->image);
}
}
文章来源:http://www.cnblogs.com/hello-tl/p/7592974.html
PHP:GD库 图片水印处理的更多相关文章
- GD库 图片缩略图 图片水印
/** * GD库 图片缩略图 *//*$image = imagecreatefromjpeg("1.jpg");var_dump($image);exit;$width = i ...
- php笔记之GD库图片创建/简单验证码
燕十八 公益PHP培训 课堂地址:YY频道88354001 学习社区:www.zixue.it php画图:比如说验证码,缩略图,加水印都要用到GD库,所以要开启gd2库,才能用 首先找到php.in ...
- php课程 8-32 如何使用gd库进行图片裁剪和缩放
php课程 8-32 如何使用gd库进行图片裁剪和缩放 一.总结 一句话总结:图片缩放到图片裁剪就是改变原图截取的位置以及截取的宽高. 1.电商网站那么多的图片,如果全部加载卡得慢的很,所以他们是怎么 ...
- PHP面向对象——GD库实现图片水印和缩略图
今天的实现目标就是使用GD库完成对图片加水印和图 片缩略图两个功能 动身前逻辑准备 属性: 路径 功能: 构造方法 生成水印的方法 获取 图片信息 获取位置信息(123 456 789) 创建图片资源 ...
- php使用GD库实现图片水印和缩略图——封装成类
学完了如何使用GD库来实现对图片的各种处理,那么我们可以发现,不管哪种方法,都有相似之处,如果我们把这些相似的地方和不相似的地方都封装成类,这样就可以提升代码的速度,而且节省了很多时间,废话不多说,来 ...
- php使用GD库实现图片水印和缩略图——生成图片缩略图
今天呢,就来学习一下在php中使用PD库来实现对图片水印的文字水印方法,不需要PS哦! 首先,准备素材 (1)准备一张图片 (2)准备一张水印(最好是透明的,即背景是白色底) (3)准备一中字体(在电 ...
- php使用GD库实现图片水印和缩略图——给图片添加图片水印
今天呢,就来学习一下在php中使用PD库来实现对图片水印的文字水印方法,不需要PS哦! 首先,准备素材 (1)准备一张图片 (2)准备一张水印(最好是透明的,即背景是白色底) (3)准备一中字体(在电 ...
- php使用GD库实现图片水印和缩略图——给图片添加文字水印
今天呢,就来学习一下在php中使用PD库来实现对图片水印的文字水印方法,不需要PS哦! 首先,准备素材 (1)准备一张图片 (2)准备一张水印(最好是透明的,即背景是白色底) (3)准备一中字体(在电 ...
- 使用GD库做图片水印
png图片作为水印加到其他类型图片后,背景变黑色 原因: imagecopy函数拷贝时可以保留png图像的原透明信息,而imagecopymerge却不支持图片的本身的透明拷贝. 然后直接上代码: / ...
随机推荐
- 51nod 1122 机器人走方格 V4 【矩阵快速幂】
首先建立矩阵,给每个格子编号,然后在4*4的格子中把能一步走到的格子置为1,然后乘n次即可,这里要用到矩阵快速幂 #include<iostream> #include<cstdio ...
- Python网络爬虫与信息提取
1.Requests库入门 Requests安装 用管理员身份打开命令提示符: pip install requests 测试:打开IDLE: >>> import requests ...
- pip 的具体含义
Python 2.7.9 and later (on the python2 series), and Python 3.4 and later include pip (pip3 for Pytho ...
- logstsh | logstash-input-jdbc 启动错误收集
1: Failed to execute action {:action=>LogStash::PipelineAction::Create/pipeline_id:main, :excepti ...
- pytest的参数化
参数化有两种方式: 1. @pytest.mark.parametrize 2.利用conftest.py里的 pytest_generate_tests 1中的例子如下: @pytest.mark. ...
- [POI2001]Gra绿色游戏
Description 绿色游戏是一种两人游戏,双方分别称Ann和Billy.游戏的内容主要是轮流在棋盘上移动一颗棋子.棋盘上的点一部分是绿色的,其余是白色的:全部从1至a+b编号.编号1至a的点属于 ...
- 题解报告:hdu 2602 Bone Collector(01背包)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Problem Description Many years ago , in Teddy’s ...
- C# 判断文件和文件夹是否存在并创建
C# 判断文件和文件夹是否存在并创建 using System; using System.Data; using System.Configuration; using System.Collect ...
- cloudera-scm-server启动出现Error creating bean with name 'entityManagerFactoryBean'与HHH010003: JDBC Driver class not found: com.mysql.jdbc.Driver错误解决办法(图文详解)
不多说,直接上干货! 问题详情 -- ::, INFO main:com.cloudera.server.cmf.Main: Starting SCM Server. JVM Args: [-Dlog ...
- 移动端如何定义字体font-family
移动端如何定义字体font-family 中文字体使用系统默认即可,英文用Helvetica /* 移动端定义字体的代码 */ body{font-family:Helvetica;} 参考<移 ...