跟踪function()

搜索(filemanager/upload.php)

在代码中发现,上传成功后,会传回JSON信息数据,于是最后找到方法是

$upload_handler = new UploadHandler($uploadConfig, true, $messages);

同时大叔发现upload.php自己没有uploadhandler()方法,但是引入入

require('UploadHandler.php');
$messages = null;

于是乎

搜索(filemanager/UploadHandler.php)

在代码中发现UploadHandler{}是个大类,只能继续在里面找方法

发现判断尺寸真实有效时,会判断是否为post传值,如果是会将数据进行操作

if ($initialize) {
$this->initialize();
} protected function initialize()
{
switch ($this->get_server_var('REQUEST_METHOD')) {
...
case 'POST':
$this->post($this->options['print_response']);
break;
...
}
}

于是查看post()方法,发现handle_file_upload()方法中放进了所有的POST图片信息

public function post($print_response = true)
{
...
$files[] = $this->handle_file_upload(
isset($upload['tmp_name']) ? $upload['tmp_name'] : null,
$file_name ? $file_name : (isset($upload['name']) ?
$upload['name'] : null),
$size ? $size : (isset($upload['size']) ?
$upload['size'] : $this->get_server_var('CONTENT_LENGTH')),
isset($upload['type']) ?
$upload['type'] : $this->get_server_var('CONTENT_TYPE'),
isset($upload['error']) ? $upload['error'] : null,
null,
$content_range
);
...
}

查看handle_file_upload()方法,终于找到了move_uploaded_file()方法,按方法逻辑和两个参数的值,他正在将post临时图片上传至程序图片文件夹内。

protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index = null, $content_range = null)
{
...
move_uploaded_file($uploaded_file, $file_path);
...
}

于是大叔决定在该函数下增加一个加水印的方法,让他可以对上传的每一张图片操作,但是无论怎么写,只要一有操作方法就会各种提示错误,于是只能放弃。

这时大叔记起,插件的缩略并不是直接生成的,他的流程是:

上传图片成功->重新刷新dialog.php->判断有新图片存在->自动生成缩略图

于是大叔开始查看插件自动生成缩略图的方法,结果一找就找到了,他正好就在上传图片的方法下面。

protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index = null, $content_range = null)
{
...
if ($this->is_valid_image_file($file_path)) {
$this->handle_image_file($file_path, $file);
}
...
}

于是大叔将水印方法写在下面

if ($this->is_valid_image_file($file_path)) {

    //自动生成缩略图
$this->handle_image_file($file_path, $file); //===========================水印图片.S
$src_path = 'mark.png'; //水印图片
$dst_path = $file_path; //需要添加水印图片
//创建图片的实例
$dst = imagecreatefromstring(file_get_contents($dst_path));
$src = imagecreatefromstring(file_get_contents($src_path));
//获取水印图片的宽高
list($src_w, $src_h) = getimagesize($src_path);
//获取要加水印图片的宽高
list($dst_w, $dst_h) = getimagesize($dst_path);
//将水印图片复制到目标图片上,最后个参数50是设置透明度,这里实现半透明效果
//imagecopymerge($dst, $src, 10, 10, 0, 0, $src_w, $src_h, 50);
//如果水印图片本身带透明色,则使用imagecopy方法
imagecopy($dst, $src, ($dst_w - $src_w - 10), ($dst_h - $src_h - 10), 0, 0, $src_w, $src_h);
//输出图片
list($dst_w, $dst_h, $dst_type) = getimagesize($dst_path);
switch ($dst_type) {
case 1://GIF
header('Content-Type: image/gif');
imagegif($dst);
break;
case 2://JPG
header('Content-Type: image/jpeg');
imagejpeg($dst);
break;
case 3://PNG
header('Content-Type: image/png');
imagepng($dst);
break;
default:
break;
} //清除图片缓存
imagedestroy($dst);
imagedestroy($src);
//===========================水印图片.E }

上传邓妞...

测试成功!


感谢:

TinyMCE插件:RESPONSIVE filemanager 9 图片自动添加水印的更多相关文章

  1. jQuery图片自动添加水印插件

    JS脚本(jQuery)为图片加水印效果预览:http://hovertree.com/texiao/jquery/94/ 本功能使用HTML5实现,可为图片加上文字水印,可设置文字,设置颜色,位置等 ...

  2. TinyMCE插件:FileManager [4.x-6.x] 配置及BUG处理

    FileManager最新版已升级到9.x,9.x新增了对文件的批量处理,但仍然有部分同学在继续使用6.x,这里大叔整理了一份自己在配置6.x时,遇到的问题和解决方案. 安装 下载安装包解压后,在根目 ...

  3. TinyMCE插件:Filemanager [4.x-6.x] 图片自动添加水印

    上传图片程序(filemanager/upload.php) 在if (!empty($_FILES) && $upload_files)有一个move_uploaded_file() ...

  4. ASP.NET给图片自动添加水印

    先建一个类,感觉注释已经很详细了,有不懂的欢迎评论 using System; using System.Collections.Generic; using System.Drawing; usin ...

  5. TinyMCE插件:Filemanager [4.x-6.x] 文件名统一格式化

    上传图片程序(filemanager/upload.php) 在if (!empty($_FILES) && $upload_files)中上传图片时,在文件正式上传至服务器前,有一次 ...

  6. TinyMCE插件:RESPONSIVE filemanager 9 安装与配置

    RESPONSIVE filemanager 功能: 文件上传 文件下载 重命名文件 删除文件 新建文件夹 为每个用户创建子目录 上传文件效果图: 浏览文件效果图: 文件说明: filemanager ...

  7. [转]响应式表格jQuery插件 – Responsive tables

    本文转自:http://www.shejidaren.com/responsive-tables-for-bootstrap-3.html 这个Responsive tables jQuery插件依赖 ...

  8. DedecmsV5.7本地上传缩略图无法自动添加水印的解决方法

    问题:dedecms后台 系统->图片水印设置 图片水印设置有开启了,但是本地上传缩略图无法自动添加水印 网上有很多资料,所以记录一下 1.打开dede(实际项目后台文件夹)/archives_ ...

  9. Dedecms本地上传缩略图无法自动添加水印的解决方法

    客户遇到一个问题,DEDECMS(V5.7)后台添加文档时,本地上传缩略图无法自动添加水印(系统设置里的图片水印设置没有问题),找了半天,终于找到了解决方法,留个记号: 打开dede/archives ...

随机推荐

  1. JavaScript JSON AJAX 同源策略 跨域请求

    网页和Ajax和跨域的关系 1 Ajax使网页可以动态地.异步地的与服务器进行数据交互,可以让网页局部地与服务器进行数据交互 2 Ajax强调的是异步,但是会碰到跨域的问题. 3 而有很多技术可以解决 ...

  2. 八、word-space与letter-space

    1.worde-space是增加或减少单词之间的空白,即字间距.例如: this     is      a     bag   2.letter-space是增加或减少字符间的空白,即字符间距.例如 ...

  3. AdvStringGrid入门使用

    仅仅把数据从数据库中显示到AdvStringGrid中 procedure TForm1.btnQueryClick(Sender: TObject); var i, j: Integer; begi ...

  4. sqlserver索引维护(重新组织生成索引)

    sqlserver索引的维护 1:查看索引碎片大于百分三十以上的索引 select object_id= object_id,indexid = index_id,partitionnum = par ...

  5. C# 转换运算符:implicit(隐式),explicit(显示)

    //A类 class Cls1 { public string name; //构造函数 public Cls1(string name) { this.name = name; } //implic ...

  6. JSP的重定向有两种forward和sendRedirect

    jsp:forward重定向 当index.jsp存放在tomcat服务器应用目录下时:D:\Tomcat 7.0\webapps\Spring_shizhan4ban_Chapter05\index ...

  7. 在ubuntu16.04上安装eclipse

     在ubuntu16.04上安装eclipse 一.下载     首先我们需要安装jdk1.8及其以上,然后从官网:https://www.eclipse.org/downloads/上下载,需要注意 ...

  8. FireFox浏览器Flash&视频下载工具推荐

    介绍 两款扩展组件:Flash and Video Download & Flash Video Downloader 一起使用,各有优缺点. Flash and Video Download ...

  9. [python]emlog相册插件getshell exploit

    昨天本站转载了emlog相册插件的漏洞分析文章,当然也有html版的getshell代码,喜欢的同学们可以直接用昨天文章中分享的代码.为了练习python,小弟用python又重写了一次,喜欢的同学们 ...

  10. mysql 修改已存在的表增加ID属性为auto_increment自动增长

    今天有需要将已经存在表设置自动增长属性 具体如下 alter table customers change id id int not null auto_increment primary key; ...