齐博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,一经查实,立即删除!

相关文章

【HDU - 1285】确定比赛名次 (拓扑排序)

题干&#xff1a; 有N个比赛队&#xff08;1<N<500&#xff09;&#xff0c;编号依次为1&#xff0c;2&#xff0c;3&#xff0c;。。。。&#xff0c;N进行比赛&#xff0c;比赛结束后&#xff0c;裁判委员会要将所有参赛队伍从前往后依次排名&#xff0c;但现在裁判委…

mysql dql_Mysql中的DQL查询语句

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

【POJ - 1028】 Web Navigation( 栈 or 模拟队列 )

题干&#xff1a; Standard web browsers contain features to move backward and forward among the pages recently visited. One way to implement these features is to use two stacks to keep track of the pages that can be reached by moving backward and forward. …

python循环post请求_循环post请求太多

我正在做一个scrapy spider&#xff0c;我必须发送一个post请求循环才能转到下一个页面&#xff0c;问题是它只发送一个post请求。querystring更改每个页面的元素“currentPage”&#xff0c;因此我必须为每个页面更改此键的值并发送post。但是&#xff0c;正如我之前所说&…

【POJ - 2387】 Til the Cows Come Home(单源最短路Dijkstra算法)

题干&#xff1a; Bessie is out in the field and wants to get back to the barn to get as much sleep as possible before Farmer John wakes her for the morning milking. Bessie needs her beauty sleep, so she wants to get back as quickly as possible. Farmer Jo…

递归Java_递归的Java实现

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

【HDU - 2112】 HDU Today(dijkstra单源最短路 + map转换)

题干&#xff1a; HDU Today Time Limit : 15000/5000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submission(s) : 11 Accepted Submission(s) : 5 Problem Description 经过锦囊相助&#xff0c;海东集团终于度过了危机&#xff0c;从此&#…

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

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

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

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

算法--背包九讲(详细讲解+代码)

背包九讲 目录 第一讲 01背包问题 第二讲 完全背包问题 第三讲 多重背包问题 第四讲 混合三种背包问题 第五讲 二维费用的背包问题 第六讲 分组的背包问题 第七讲 有依赖的背包问题 第八讲 泛化物品 第九讲 背包问题问法的变化 附&#xff1a;USACO中的背包问题 前…

java中白盒测试用例_基于JAVA开发的中国象棋游戏的开发与研究白盒测试用例.doc...

中国象棋白盒测试用例文件状态当前版本V1.0草稿作 者梁世聪完成日期2012/6/17文档模板SSP-VER-T13-V1.0密 级变更历史版本完成日期变更记录作者批准签字V1.02012/6/17无梁世聪梁世聪目 录目录1 目的12 范围13 被测模块列表14 模块逻辑结构14.1 模块逻辑结构图14.2 模块功能定义…

【POJ - 1502】MPI Maelstrom(Dijkstra单源最短路--求一点到其余个点的最小值的最大值)

题干&#xff1a; BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distributed shared memory machine with a hierarchical communication subsystem. Valentine McKees research advisor, Jack Swigert, has asked her to ben…

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

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

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

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

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

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

【POJ-3259】 Wormholes(判负环,spfa算法)

题干&#xff1a; While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way path that delivers you to its destination at a time that is BEFORE you entered the wormhole! Eac…

【HihoCoder - 1550】顺序三元组(思维)

题干&#xff1a; 给定一个长度为N的数组A[A1, A2, ... AN]&#xff0c;已知其中每个元素Ai的值都只可能是1, 2或者3。 请求出有多少下标三元组(i, j, k)满足1 ≤ i < j < k ≤ N且Ai < Aj < Ak。 Input 第一行包含一个整数N 第二行包含N个整数A1, A2, ... …

joptionpane java_Java JOptionPane

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

【POJ - 3268 】Silver Cow Party(Dijkstra最短路+思维)

题干&#xff1a; One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the big cow party to be held at farm #X (1 ≤ X ≤ N). A total of M (1 ≤ M ≤ 100,000) unidirectional (one-way roads connects pairs of farms; roa…

【HDU - 3342】Legal or Not(拓扑排序)

题干&#xff1a; ACM-DIY is a large QQ group where many excellent acmers get together. It is so harmonious that just like a big family. Every day,many "holy cows" like HH, hh, AC, ZT, lcc, BF, Qinz and so on chat on-line to exchange their ideas.…