Ueditor安装包,里面有个/php/文件夹,找到Uploader.class.php,这是通用上传类文件
找到private function upFile(),这是上传文件的主处理方法,找到122行:$this->stateInfo = $this->stateMap[0]; ,在这个下面加入:$this->imageWaterMark($this->filePath,9,'logo.png'); imageWaterMark是自定义的函数,在下面会讲到,$this->filePath 这是上传图片的路径,9 表示的是水印的位置,在右下角,logo.png这个就是你要添加的水印图片了,这个在同一目录下/php/,如果要放到其它路径请用相对路径。

下面这个就是自定义函数了,添加到Uploader 类中

/*

* 功能:PHP图片水印 (水印支持图片或文字)
* 参数:
*$groundImage 背景图片,即需要加水印的图片,暂只支持GIF,JPG,PNG格式;
*$waterPos水印位置,有10种状态,0为随机位置;
*1为顶端居左,2为顶端居中,3为顶端居右;
*4为中部居左,5为中部居中,6为中部居右;
*7为底端居左,8为底端居中,9为底端居右;
*$waterImage图片水印,即作为水印的图片,暂只支持GIF,JPG,PNG格式;
*$waterText文字水印,即把文字作为为水印,支持ASCII码,不支持中文;
*$textFont文字大小,值为1、2、3、4或5,默认为5;
*$textColor文字颜色,值为十六进制颜色值,默认为#FF0000(红色);
*
* 注意:Support GD 2.0,Support FreeType、GIF Read、GIF Create、JPG 、PNG
*$waterImage 和 $waterText 最好不要同时使用,选其中之一即可,优先使用 $waterImage。
*当$waterImage有效时,参数$waterString、$stringFont、$stringColor均不生效。
*加水印后的图片的文件名和 $groundImage 一样。
*/
private function imageWaterMark($groundImage,$waterPos=0,$waterImage="",$waterText="",$textFont=5,$textColor="#FF0000")
{
$isWaterImage = FALSE;
$formatMsg = "暂不支持该文件格式,请用图片处理软件将图片转换为GIF、JPG、PNG格式。";
//读取水印文件
if(!empty($waterImage) && file_exists($waterImage))
{
$isWaterImage = TRUE;
$water_info = getimagesize($waterImage);
$water_w = $water_info[0];//取得水印图片的宽
$water_h = $water_info[1];//取得水印图片的高 
switch($water_info[2])//取得水印图片的格式
{
case 1:$water_im = imagecreatefromgif($waterImage);break;
case 2:$water_im = imagecreatefromjpeg($waterImage);break;
case 3:$water_im = imagecreatefrompng($waterImage);break;
default:die($formatMsg);
}
}
//读取背景图片
if(!empty($groundImage) && file_exists($groundImage))
{
$ground_info = getimagesize($groundImage);
$ground_w = $ground_info[0];//取得背景图片的宽
$ground_h = $ground_info[1];//取得背景图片的高
switch($ground_info[2])//取得背景图片的格式
{
case 1:$ground_im = imagecreatefromgif($groundImage);break;
case 2:$ground_im = imagecreatefromjpeg($groundImage);break;
case 3:$ground_im = imagecreatefrompng($groundImage);break;
default:die($formatMsg);
}
}
else
{
die("需要加水印的图片不存在!");
}
//水印位置
if($isWaterImage)//图片水印
{
$w = $water_w;
$h = $water_h;
$label = "图片的";
}
else//文字水印
{
$temp = imagettfbbox(ceil($textFont*5),0,"./cour.ttf",$waterText);//取得使用 TrueType 字体的文本的范围
$w = $temp[2] - $temp[6];
$h = $temp[3] - $temp[7];
unset($temp);
$label = "文字区域";
}
if( ($ground_w<$w) || ($ground_h<$h) )
{
echo "需要加水印的图片的长度或宽度比水印".$label."还小,无法生成水印!";
return;
}
switch($waterPos)
{
case 0://随机
$posX = rand(0,($ground_w - $w));
$posY = rand(0,($ground_h - $h));
break;
case 1://1为顶端居左
$posX = 0;
$posY = 0;
break;
case 2://2为顶端居中
$posX = ($ground_w - $w) / 2;
$posY = 0;
break;
case 3://3为顶端居右
$posX = $ground_w - $w;
$posY = 0;
break;
case 4://4为中部居左
$posX = 0;
$posY = ($ground_h - $h) / 2;
break;
case 5://5为中部居中
$posX = ($ground_w - $w) / 2;
$posY = ($ground_h - $h) / 2;
break;
case 6://6为中部居右
$posX = $ground_w - $w;
$posY = ($ground_h - $h) / 2;
break;
case 7://7为底端居左
$posX = 0;
$posY = $ground_h - $h;
break;
case 8://8为底端居中
$posX = ($ground_w - $w) / 2;
$posY = $ground_h - $h;
break;
case 9://9为底端居右
$posX = $ground_w - $w - 10; // -10 是距离右侧10px 可以自己调节
$posY = $ground_h - $h - 10; // -10 是距离底部10px 可以自己调节
break;
default://随机
$posX = rand(0,($ground_w - $w));
$posY = rand(0,($ground_h - $h));
break;
}
//设定图像的混色模式
imagealphablending($ground_im, true);
if($isWaterImage)//图片水印
{
imagecopy($ground_im, $water_im, $posX, $posY, 0, 0, $water_w,$water_h);//拷贝水印到目标文件 
}
else//文字水印
{
if( !emptyempty($textColor) && (strlen($textColor)==7) )
{
$R = hexdec(substr($textColor,1,2));
$G = hexdec(substr($textColor,3,2));
$B = hexdec(substr($textColor,5));
}
else
{
die("水印文字颜色格式不正确!");
}
imagestring ( $ground_im, $textFont, $posX, $posY, $waterText, imagecolorallocate($ground_im, $R, $G, $B)); 
}
//生成水印后的图片
@unlink($groundImage);
switch($ground_info[2])//取得背景图片的格式
{
case 1:imagegif($ground_im,$groundImage);break;
case 2:imagejpeg($ground_im,$groundImage);break;
case 3:imagepng($ground_im,$groundImage);break;
default:die($errorMsg);
}
//释放内存
if(isset($water_info)) unset($water_info);
if(isset($water_im)) imagedestroy($water_im);
unset($ground_info);
imagedestroy($ground_im);
}

帝国cms更换Ueditor编辑器上传图片加水印的更多相关文章

  1. 使用Ueditor编辑器上传图片总结;

    今天使用Ueditor编辑器上传图片一直出问题,在网上找了多种方法,最后总结如下: Ueditor编辑器是百度开发的编辑器,要在jsp页面添加Ueditor编辑器,需要以下几步: (1)到 http: ...

  2. Web 上传图片加水印

    上传图片加水印 需要使用控件FileUpload 上传按钮Image控件展示上传的图片,页面中拖入三个控件 <form id="form1" runat="serv ...

  3. 织梦更换Ueditor编辑器后栏目内容提交更新失败

    今天在使用网友的相关经验<百度编辑器(Ueditor)整合到dedecms>,给织梦dedecms系统更换编辑器后,文章编辑器使用正常,在编辑栏目内容的时候,出现提交后不更新内容的情况,上 ...

  4. 在linux下使用百度ueditor编辑器上传图片

    百度ueditor编辑器虽然强大,但是也有不足的地方.如果对ueditor流程不是很熟悉可以说走的弯路比较多,费力不讨好.下面呢,就是要解决ueditor遇到的问题. 用ueditor上传图片遇到的问 ...

  5. .Net 下FCKeditor上传图片加水印

    配置FCKEditor请参考网上的. 如果你用的是.net的FCKEditor,把用到的FCKEditor.Net项目解压缩 在FCKEditor.net项目中,依次找到FileBrowser--&g ...

  6. C# Asp.net 修改Ueditor编辑器上传图片保存路径

    默认情况下Ueditor图片上传的保存路径是在/ueditor/net/upload/目录下,(如:http://localhost/ueditor/net/upload/123.png), 但是有时 ...

  7. ASP.NET配置Ueditor编辑器上传图片路径

    1.配置ueditor/editor_config.js文件,将 //图片上传配置区 ,imageUrl:URL+"net/imageUp.ashx" //图片上传提交地址 ,im ...

  8. UEditor编辑器上传图片开发流程

    在ueditor目录下找到uedior.config.js,找到如下三行: ,imageUrl: "<%=path %>/controller.json" //图片上传 ...

  9. Webform 上传图片加水印

    界面: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx ...

随机推荐

  1. 【转载】WPS通过设置密码的方式对Excel文件加密

    有时候Excel文件中可能包含一些敏感数据,此时希望对Excel文件进行加入密码的形式进行加密保护,在WPS软件和Office Excel软件中都支持对Excel文件进行密码保护,设置了密码保护的Ex ...

  2. java基本结构

    前言 Java文件的运行过程: 1,javac.exe:编译器 2,java.exe:解释器 微软shell下运行实例: C:\Users\Administrator>cd D:\文档\JAVA ...

  3. Redhat下安装SAP的相关

    Red Hat Enterprise Linux 6.x: Installation and Upgrade - SAP Note 1496410 Red Hat Enterprise Linux 7 ...

  4. .net core jenkins持续集成

    执行 Shell pwd ls echo ${PATH} whoami which dotnet dotnet --info dotnet --version echo '============== ...

  5. eclipse svn 提交、更新报错

    问题描述: svn: Unable to connect to a repository at URL 'https://test.com/svn/clouds/trunk/fire_Alarm'sv ...

  6. web之表单form

    表单是我们平常编写Web应用常用的工具,表单(<form>)用来收集用户提交的数据,发送到服务器.比如,用户提交用户名和密码,让服务器验证,就要通过表单.表单是一个包含表单元素或控件的区域 ...

  7. linux设备驱动程序-i2c(1):i2c总线的添加与实现

    linux设备驱动程序-i2c(1):i2c总线的添加与实现 (基于4.14内核版本) 在上一章节linux设备驱动程序-i2c(0)-i2c设备驱动源码实现中,我们演示了i2c设备驱动程序的源码实现 ...

  8. robotframework+Python3.7 接口自动化测试

    具体的测试用例,password,channel,resultCode传给接口描述 集成了一些常见的测试接口方法 1. Get请求下,

  9. LeetCode LCP 3 机器人大冒险

    题目解析: 对于本题主要的核心是对于一个指令字符串如“RURUU”,如果我们假设它的终点坐标为(8,8),其实只要统计指令字符串中的R的个数和U的个数(对于我给出的例子而言,num_R == 2,nu ...

  10. Kotlin协程作用域与构建器详解

    在上次我们是通过了这种方式来创建了一个协程: 接着再来看另一种创建协程的方式: 下面用它来实现上一次程序一样的效果,先来回顾一下上一次程序的代码: 好,下面改用runBlocking的方式: 运行一下 ...