基于已给出的各种图像操作方法,这里我总结出了PHP图像操作的一个类,包含给图像加入文字水印、图像水印和压缩图片。

读者可自行加入功能。

<?

php

class Image {

	private $info;
private $type;
private $iamge; /**
* 打开图片,写入内存
*
**/
public function __construct($src)
{
$this->info = getimagesize($src);
$this->type = image_type_to_extension($this->info[2],false);
$fun = "imagecreatefrom".$this->type;
$this->image = $fun($src);
} //缩略图
public function thumb($width, $height)
{
$image_thumb = imagecreatetruecolor($width, $height);
imagecopyresampled($image_thumb, $this->image, 0, 0, 0, 0, $width, $height, $this->info[0], $this->info[1]);
imagedestroy($this->image);
$this->image = $image_thumb;
} //文字水印
public function fontMark($content, $fontUrl, $size, $color, $locate=array('x'=>0,'y'=>0), $angle=0)
{
$color = imagecolorallocatealpha($this->image, $color[0], $color[1], $color[2], $color[3]);
imagettftext($this->image, $size, $angle, $locate['x'], $locate['y'], $color, $fontUrl, $content);
} //图片水印
public function imageMark($src,$locate,$alpha)
{
$info2 = getimagesize($src);
$type2 = image_type_to_extension($info2[2],false);
$fun2 = "imagecreatefrom".$type2;
$water = $fun2($src);
imagecopymerge($this->image, $water, $locate['x'], $locate['y'], 0, 0, $info2[0], $info2[1], $alpha);
imagedestroy($water);
} //在浏览器中显示
public function show()
{
header("Content-type:".$this->info['mime']);
$fun = "image".$this->type;
$fun($this->image);
} //保存为文件
public function save($newname)
{
$fun = "image".$this->type;
$fun($this->image, $newname.'.'.$this->type);
} public function __destruct()
{
imagedestroy($this->image);
}
}

PHP图像操作类的更多相关文章

  1. C#中Bitmap类 对图像の操作 可检测图片完整性

    try { Bitmap bm = new Bitmap(pics[ip]); BitmapToBytes(bm).Reverse().Take(2); } catch (Exception ex) ...

  2. 2014 年10个最佳的PHP图像操作库

    2014 年10个最佳的PHP图像操作库   Thomas Boutell 以及众多的开发者创造了以GD图形库闻名的一个图形软件库,用于动态的图形计算. GD提供了对于诸如C, Perl, Pytho ...

  3. 2014 年10个最佳的PHP图像操作库--留着有用

    Thomas Boutell 以及众多的开发者创造了以GD图形库闻名的一个图形软件库,用于动态的图形计算. GD提供了对于诸如C, Perl, Python, PHP, OCaml等等诸多编程语言的支 ...

  4. 10个最佳的PHP图像操作库

    Thomas Boutell 以及众多的开发者创造了以GD图形库闻名的一个图形软件库,用于动态的图形计算. GD提供了对于诸如C, Perl, Python, PHP, OCaml等等诸多编程语言的支 ...

  5. C# 文件操作类大全

      C# 文件操作类大全 时间:2015-01-31 16:04:20      阅读:1724      评论:0      收藏:0      [点我收藏+] 标签: 1.创建文件夹 //usin ...

  6. 学习笔记TF015:加载图像、图像格式、图像操作、颜色

    TensorFlow支持JPG.PNG图像格式,RGB.RGBA颜色空间.图像用与图像尺寸相同(height*width*chnanel)张量表示.通道表示为包含每个通道颜色数量标量秩1张量.图像所有 ...

  7. C#全能数据库操作类及调用示例

    C#全能数据库操作类及调用示例 using System; using System.Data; using System.Data.Common; using System.Configuratio ...

  8. WorldWind源码剖析系列:图像助手类ImageHelper

    图像助手类ImageHelper封装了对各种图像的操作.该类类图如下. 提供的主要处理方法基本上都是静态函数,简要描述如下: public static bool IsGdiSupportedImag ...

  9. 【知识必备】ezSQL,最好用的数据库操作类,让php操作sql更简单~

    最近用php做了点小东东,用上了ezSQL,感觉真的很ez,所以拿来跟大家分享一下~ ezSQL是一个非常好用的PHP数据库操作类.著名的开源博客WordPress的数据库操作就使用了ezSQL的My ...

随机推荐

  1. BZOJ 1303

    思路: 水题  竟然不会做 尴尬 比b大的数=1 比b小的数=-1 找到b 统计一下左边比b大x的数有多少 扫右边的时候就查左边的表 就可以了 //By SiriusRen #include < ...

  2. BZOJ 3653 主席树

    思路: (抄一波公式) $$ans=min(dep[x],k)×(size[x]-1)+\sum_{y在x的子树中,且dis(x,y)<=k}(size[y]-1)$$ 顺着DFS序 按照dee ...

  3. 安卓手机USB无法共享、上网或卡顿的解决方法

    安卓手机通过USB为电脑(Windows10)提供网络接入点时,系统程序会异常卡顿. 1)设备管理器2)点击“网络适配器”,在弹出的下拉列表中选择”Remote NDIS based Internet ...

  4. An interesting scroll background------ActionScript3.0

    package { /* *@ ClassName : package::backGround *@ INTRO : the continuously scroll background *@ Aut ...

  5. react基础篇三

    事件处理 React事件绑定属性的命名采用驼峰式写法,而不是小写. 如果采用 JSX 的语法你需要传入一个函数作为事件处理函数,而不是一个字符串(DOM元素的写法) 例如,传统的 HTML: < ...

  6. Arduino 红外接收

    一.实物图 二.例子代码 注:git clone https://github.com/z3t0/Arduino-IRremote.git 放到Arduino 的libraries目录下面  从遥控器 ...

  7. Python-logging模块的初级使用

    这篇文章适合刚接触logging模块,想快速使用 并看到使用效果的童鞋.如果想全面的了解logging模块,请移步~ 直接上代码+注释 #1.导入模块logging import logging #2 ...

  8. vue货币格式化组件、局部过滤功能以及全局过滤功能

    一.在这里介绍一个vue的时间格式化插件: moment 使用方法: .npm install moment --save. 2 定义时间格式化全局过滤器 在main.js中 导入组件 import ...

  9. python tips:matplotlib保存多张图片时,图片会相互叠加

    问题: 使用matplotlib的pyplot.savefig保存图片时,前面的图会不断叠加到后面的图中. 原因: savefig方法保存图片并不会重置画布,所以导致图片的相互叠加. 解决方法: 保存 ...

  10. Linux下文件查找命令find笔记

    在Linux命令下如果需要快速自己系统所需要处理的文件,可以通过find命令快速进行检索. 如果想在某个路径下查找相应的文件可以执行如下命令: find path -name filename # p ...