齐博php百度编辑器上传图片_php版百度编辑器ueditor怎样给上传图片自动添加水印?...

百度ueditor是广泛使用的所见即所得图文排版编辑插件,功能比较完善,美中不足就是不支持自动加水印。万维景盛工程师搜集到php版ueditor自动加水印的教程,希望对大家有帮助。

eca1f3a635bda4944177841194d95861.png

1.打开ueditor目录下的php目录下的config.json 文件

在上传配置项添加下面代码:

"iswatermark": "true",

2.打开ueditor目录下的php目录下的action_upload.php文件,搜索代码:case 'uploadimage':

$config = array(

"pathFormat" => $CONFIG['imagePathFormat'],

"maxSize" => $CONFIG['imageMaxSize'],

"allowFiles" => $CONFIG['imageAllowFiles']

);

$fieldName = $CONFIG['imageFieldName'];

break;

在“break;”前添加:$watermark =

$CONFIG['is

watermark

']

;

这句话就可以读取配置文件的"iswatermark"值了。

继续在这个文件搜索代码:$up = new Uploader($fieldName, $config, $base64);

把它改成:$up = new Uploader($fieldName, $config, $base64, $watermark);

这样就可以实例化Uploader类时带上$watermark变量。

3.这是最后一步,也是最重要的一步。打开ueditor目录下的php目录下的Uploader.class.php文件。

在这个类里面添加private $water; //是否添加水印(属性)

这句话。

把构造方法改成public function __construct($fileField, $config, $type = "upload", $watermark = false)

在构造方法里面写上  ($this->water = $watermark; )这句话。

在upFile 方法内部后面添加以下代码:if( $this->water ){

$this->watermark($this->filePath,$this->filePath);

}

在这个类文件里添加以下方法,实现图片添加水印就靠它了。【*

* 图片加水印

* $source  string  图片资源

* $target  string  添加水印后的名字

* $w_pos   int     水印位置安排(1-10)【1:左头顶;2:中间头顶;3:右头顶...值空:随机位置】

* $w_img   string  水印图片路径

* $w_text  string  显示的文字

* $w_font  int     字体大小

* $w_color string  字体颜色

*】

public function watermark($source, $target = '', $w_pos = '', $w_img = '', $w_text = 'www.aiyu.com',$w_font = 10, $w_color = '#CC0000') {

$this->w_img = '../watermark.png';//水印图片

$this->w_pos = 9;

$this->w_minwidth = 400;//最少宽度

$this->w_minheight = 200;//最少高度

$this->w_quality = 80;//图像质量

$this->w_pct = 85;//透明度

$w_pos = $w_pos ? $w_pos : $this->w_pos;

$w_img = $w_img ? $w_img : $this->w_img;

if(!$this->check($source)) return false;

if(!$target) $target = $source;

$source_info = getimagesize($source);//图片信息

$source_w  = $source_info[0];//图片宽度

$source_h  = $source_info[1];//图片高度

if($source_w w_minwidth || $source_h w_minheight) return false;

switch($source_info[2]) { //图片类型

case 1 : //GIF格式

$source_img = imagecreatefromgif($source);

break;

case 2 : //JPG格式

$source_img = imagecreatefromjpeg($source);

break;

case 3 : //PNG格式

$source_img = imagecreatefrompng($source);

//imagealphablending($source_img,false); //关闭混色模式

imagesavealpha($source_img,true); //设置标记以在保存 PNG 图像时保存完整的 alpha 通道信息(与单一透明色相反)

break;

default :

return false;

}

if(!empty($w_img) && file_exists($w_img)) { //水印图片有效

$ifwaterimage = 1; //标记

$water_info  = getimagesize($w_img);

$width    = $water_info[0];

$height    = $water_info[1];

switch($water_info[2]) {

case 1 :

$water_img = imagecreatefromgif($w_img);

break;

case 2 :

$water_img = imagecreatefromjpeg($w_img);

break;

case 3 :

$water_img = imagecreatefrompng($w_img);

imagealphablending($water_img,false);

imagesavealpha($water_img,true);

break;

default :

return;

}

}else{

$ifwaterimage = 0;

$temp = imagettfbbox(ceil($w_font*2.5), 0, '../../texb.ttf', $w_text); //imagettfbbox返回一个含有 8 个单元的数组表示了文本外框的四个角

$width = $temp[2] - $temp[6];

$height = $temp[3] - $temp[7];

unset($temp);

}

switch($w_pos) {

case 1:

$wx = 5;

$wy = 5;

break;

case 2:

$wx = ($source_w - $width) / 2;

$wy = 0;

break;

case 3:

$wx = $source_w - $width;

$wy = 0;

break;

case 4:

$wx = 0;

$wy = ($source_h - $height) / 2;

break;

case 5:

$wx = ($source_w - $width) / 2;

$wy = ($source_h - $height) / 2;

break;

case 6:

$wx = $source_w - $width;

$wy = ($source_h - $height) / 2;

break;

case 7:

$wx = 0;

$wy = $source_h - $height;

break;

case 8:

$wx = ($source_w - $width) / 2;

$wy = $source_h - $height;

break;

case 9:

$wx = $source_w - ($width+5);

$wy = $source_h - ($height+5);

break;

case 10:

$wx = rand(0,($source_w - $width));

$wy = rand(0,($source_h - $height));

break;

default:

$wx = rand(0,($source_w - $width));

$wy = rand(0,($source_h - $height));

break;

}

if($ifwaterimage) {

if($water_info[2] == 3) {

imagecopy($source_img, $water_img, $wx, $wy, 0, 0, $width, $height);

}else{

imagecopymerge($source_img, $water_img, $wx, $wy, 0, 0, $width, $height, $this->w_pct);

}

}else{

if(!empty($w_color) && (strlen($w_color)==7)) {

$r = hexdec(substr($w_color,1,2));

$g = hexdec(substr($w_color,3,2));

$b = hexdec(substr($w_color,5));

}else{

return;

}

imagestring($source_img,$w_font,$wx,$wy,$w_text,imagecolorallocate($source_img,$r,$g,$b));

}

switch($source_info[2]) {

case 1 :

imagegif($source_img, $target);

//GIF 格式将图像输出到浏览器或文件(欲输出的图像资源, 指定输出图像的文件名)

break;

case 2 :

imagejpeg($source_img, $target, $this->w_quality);

break;

case 3 :

imagepng($source_img, $target);

break;

default :

return;

}

if(isset($water_info)){

unset($water_info);

}

if(isset($water_img)) {

imagedestroy($water_img);

}

unset($source_info);

imagedestroy($source_img);

return true;

}

public function check($image){

return extension_loaded('gd') && preg_match("/\.(jpg|jpeg|gif|png)/i", $image, $m) && file_exists($image) && function_exists('imagecreatefrom'.($m[1] == 'jpg' ? 'jpeg' : $m[1]));

}

4.设定水印图片文件

把水印图片命名为watermark.png,把它存放在ueditor目录下。如果你觉得这样不好,那么你在步骤3.4时候就写你水印图片的路径,温馨提醒一下:ueditor目录下的php目录是当前目录。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441980.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

mysql dql_Mysql中的DQL查询语句

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 Mysql中的DQL查询语句 1、查询所有列 --查询 学生 表所有记录(行) select *from 学生 --带条件的查询 select *from 学生 where 年龄19 2、查询指定的列 --查询 所有人的姓名和性别 select 姓名,性欢迎…

递归Java_递归的Java实现

递归是一种应用非常广泛的算法(或者编程技巧)。递归求解问题的分解过程,去的过程叫“递”,回来的过程叫“归”。递归需要满足的三个条件:1. 一个问题的解可以分解为几个子问题的解;2. 这个问题与分解之后的子问题,除了…

JAVA线程并发数量控制_线程同步工具(二)控制并发访问多个资源

声明:本文是《 Java 7 Concurrency Cookbook》的第三章, 作者: Javier Fernndez Gonzlez 译者:郑玉婷控制并发访问多个资源在并发访问资源的控制中,你学习了信号量(semaphores)的基本知识。在上个指南,你实…

*【51nod - 1459】迷宫游戏(记录双向权值的Dijkstra单源最短路)

题干: 你来到一个迷宫前。该迷宫由若干个房间组成,每个房间都有一个得分,第一次进入这个房间,你就可以得到这个分数。还有若干双向道路连结这些房间,你沿着这些道路从一个房间走到另外一个房间需要一些时间。游戏规定…

java 强制清除缓存_IDEA强制清除Maven缓存的方法示例

重新导入依赖的常见方式下面图中的刷新按钮,在我的机器上,并不能每次都正确导入pom.xml中写的依赖项,而是导入之前pom.xml的依赖(读了缓存中的pom.xml)。当然除了这些,还可以下面这样:存在的问题上面虽然是重新导入Mav…

ACM算法--spfa算法--最短路算法

求单源最短路的SPFA算法的全称是:Shortest Path Faster Algorithm。 SPFA算法是西南交通大学段凡丁于1994年发表的。 从名字我们就可以看出,这种算法在效率上一定有过人之处。 很多时候,给定的图存在负权边,这时类似…

knn算法python理解与预测_理解KNN算法

KNN主要包括训练过程和分类过程。在训练过程上,需要将训练集存储起来。在分类过程中,将测试集和训练集中的每一张图片去比较,选取差别最小的那张图片。如果数据集多,就把训练集分成两部分,一小部分作为验证集(假的测试…

joptionpane java_Java JOptionPane

Java JOptionPane1 Java JOptionPane的介绍JOptionPane类用于提供标准对话框,例如消息对话框,确认对话框和输入对话框。这些对话框用于显示信息或从用户那里获取输入。JOptionPane类继承了JComponent类。2 Java JOptionPane的声明public class JOptionPa…

java 股票 代码_Java中利用散列表实现股票行情的查询_java

---- 在java中,提供了一个散列表类Hashtable,利用该类,我们可以按照特定的方式来存储数据,从而达到快速检索的目的。本文以查询股票的收盘数据为例,详细地说明java中散列表的使用方法。一、散列表的原理---- 散列表&am…

【HDU - 3714 】Error Curves (三分)

题干: Josephina is a clever girl and addicted to Machine Learning recently. She pays much attention to a method called Linear Discriminant Analysis, which has many interesting properties. In order to test the algorithms efficiency, she colle…

指数循环节证明

还有关键的一步忘写了phi(m)>r的注意因为ma^r*m‘’所以phi(m)>phi(a^r)>r,所以就相当于phi(m)为循环节,不过如果指数小于phi(m)只能直接算了。。 注意这里的m与a^r是互质的上面忘写了。。 转自https://blog.csdn.net/guoshiyuan484/article/details/787…

java语言中的类可以_java 语言中的类

类一、类类是具有相同性质的一类事物的总称, 它是一个抽象的概念。它封装了一类对象的状态和方法, 是创建对象的模板。类的实现包括两部分: 类声明和类体类的声明类声明的基本格式为:[ 访问权限修饰符]c l a s s类名[extends超类][ implments实现的接口列表]{}说 明:① 访问权限…

【POJ - 3310】Caterpillar(并查集判树+树的直径求树脊椎(bfs记录路径)+dfs判支链)

题干: An undirected graph is called a caterpillar if it is connected, has no cycles, and there is a path in the graph where every node is either on this path or a neighbor of a node on the path. This path is called the spine of the caterpillar …

软件设计师下午题java_2018上半年软件设计师下午真题(三)

● 阅读下列说明和Java代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】生成器( Builder)模式的意图是将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示。图6-1所示为其类图。【Java代码】import java.util.*;class Product {priv…

java细粒度锁_Java细粒度锁实现的3种方式

最近在工作上碰见了一些高并发的场景需要加锁来保证业务逻辑的正确性,并且要求加锁后性能不能受到太大的影响。初步的想法是通过数据的时间戳,id等关键字来加锁,从而保证不同类型数据处理的并发性。而java自身api提供的锁粒度太大&#xff0c…

【POJ - 1062】【nyoj - 510】昂贵的聘礼 (Dijkstra最短路+思维)

题干: 年轻的探险家来到了一个印第安部落里。在那里他和酋长的女儿相爱了,于是便向酋长去求亲。酋长要他用10000个金币作为聘礼才答应把女儿嫁给他。探险家拿不出这么多金币,便请求酋长降低要求。酋长说:"嗯,如果…

【HDU - 5605】 geometry(水,数学题,推公式)

题干: There is a point PP at coordinate (x,y)(x,y). A line goes through the point, and intersects with the postive part of X,YX,Yaxes at point A,BA,B. Please calculate the minimum possible value of |PA|∗|PB||PA|∗|PB|. Input the first line…

matlab如何画函数的外包络曲线,怎样在MATLAB中划出一个函数的包络线?

沧海一幻觉下面是一系列关于MATLAB的包络线的程序:%这是定义了一个函数:function [up,down] envelope(x,y,interpMethod)%ENVELOPE gets the data of upper and down envelope of the known input (x,y).%% Input parameters:% x the abscissa of the g…

【51Nod - 1279】 扔盘子(思维)(on-p会超时)

题干: 有一口井,井的高度为N,每隔1个单位它的宽度有变化。现在从井口往下面扔圆盘,如果圆盘的宽度大于井在某个高度的宽度,则圆盘被卡住(恰好等于的话会下去)。 盘子有几种命运:1、…

java 内部类私有成员 能访问,为什么外部Java类可以访问内部类私有成员?

HUX布斯如果您想隐藏内部类的私有成员,您可以与公共成员定义一个接口,并创建一个实现此接口的匿名内部类。下面的例子:class ABC{private interface MyInterface{void printInt();}private static MyInterface mMember new MyInterface(){pr…