基于已给出的各种图像操作方法,这里我总结出了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. springboot配置过滤器和拦截器

    import javax.servlet.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.Http ...

  2. css3动画之1--animation小例子

    1.首先看效果 2.代码及分析 <style type="text/css"> #div1 { margin:100px; position: absolute; te ...

  3. Redis配置文件各项参数说明及性能调优

    Redis配置文件参数说明: 1. Redis默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程 daemonize no 2. 当Redis以守护进程方式运行时,Redis默 ...

  4. Android媒体解码MediaCodec MediaExtractor学习

    Android提供了MediaPlayer播放器播放媒体文件,其实MediaPlyer只是对Android Media包下的MediaCodec和MediaExtractor进行了包装,方便使用.但是 ...

  5. php正则表达式应用

    正则表达式 1.替换“/\d/”,“#”,$str:正则表达式\d 数字,替换为#,字符串 $str = "2hello 5li 6lei"; echo preg_replace( ...

  6. 用List表示多重性

    练习目标-在类中使用List作为模拟集合操作: 在本练习中,将用List实现银行与客户间的多重关系. 任务 对银行来说,可添加Bank类. Bank 对象跟踪自身与其客户间的关系.用Customer对 ...

  7. 【python】数组去重

    直接用set就行,比如: l = [1, 1, 2, 2, 3, 4, 5] s = set(l) c = [i for i in s] print c 结果为: [1, 2, 3, 4, 5] 其中 ...

  8. QS之force(1)

    force This command allows you to apply stimulus interactively to VHDL signals(not variables), Verilo ...

  9. JQuery特效之心形图片墙

    效果如图: 代码如下: <!doctype html> <html lang="en"> <head> <meta charset=&qu ...

  10. 利用jsonp进行Ajax跨域请求

    在进行Ajax请求的时候经常会遇到跨域的问题,这个时候一般就会用到jsonp. 关于json和jsonp,网上有很多原理解释,这里就不多赘述,需要的自行搜索. 下面是一个简单的ajax跨域请求示例: ...