基于已给出的各种图像操作方法,这里我总结出了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. [JZOJ3809]设备塔

    其实我并没有JZOJ的号...但既然dalao说了是JZOJ上的题,那就是了吧...... 为了封印辉之环,古代塞姆利亚大陆的人民在异空间中建造了一座设备塔. 简单的说,这座设备塔是一个漂浮在异空间中 ...

  2. collectionView必须点击两次才跳转

    今天遇到一个很奇怪的现象:collectionView必须点击两次才能跳转.具体看代码: -(void)collectionView:(UICollectionView *)collectionVie ...

  3. OAuth四种模式

    授权码模式(authorization code)----适用于网站服务端去oauth服务端申请授权 简化模式(implicit)----没有服务端,js+html页面去oauth服务端申请授权 密码 ...

  4. POJ_2594_最小路径覆盖

    Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 8085   Accepted: 3 ...

  5. Scala类型系统——高级类类型(higher-kinded types)

    高级类类型就是使用其他类型构造成为一个新的类型,因此也称为 类型构造器(type constructors).它的语法和高阶函数(higher-order functions)相似,高阶函数就是将其它 ...

  6. 学习网址Collect

    Laravel 学院    https://laravelacademy.org/wx小程序 https://developers.weixin.qq.com/miniprogram/dev/quic ...

  7. day002 计算机基础之 操作系统和编程语言的分类

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp今天主要针对计算机基础中的操作系统和编程语言的分类进行了讲解. 操作系统 &nbsp ...

  8. BZOJ2251 [2010Beijing Wc]外星联络 后缀数组 + Height数组

    Code: #include <bits/stdc++.h> #define setIO(s) freopen(s".in", "r", stdin ...

  9. PAT_A1147#Heaps

    Source: PAT A1147 Heaps (30 分) Description: In computer science, a heap is a specialized tree-based ...

  10. eas之指定虚模式

    KDTable支持三种取数模式:实模式.虚模式分页.虚模式分组,默认为实模式.// 实模式table.getDataRequestManager().setDataRequestMode(KDTDat ...