如何解决如何使用 dropzonejs 添加水印
我正在使用 dropzonejs javascript 库来上传我的图片。如何使用 dropzonejs 添加水印?
任何代码和帮助将不胜感激。
解决方法
我找到了一个使用 dropzone 的 transformFile 选项的解决方案。我已经使用了 compressorjs 库。这可以压缩文件,还可以为我们绘制水印。
var myDropzone = new Dropzone("div#myDrop",{
paramName: "file",// The name that will be used to transfer the file
addRemoveLinks: true,uploadMultiple: false,autoProcessQueue: true,parallelUploads: 50,maxFilesize: jsonData.maxFileSizeMB,// MB
acceptedFiles: ".png,.jpeg,.jpg,.gif",url: jsonData.uploadUrl,transformFile: function(file,done){
console.log('on transform file: ',file.name);
new Compressor(file,{
strict: false,drew: function (context,canvas) {
// draw your watermark to context of the canvas
},success: function (result )
{
console.log('success: ready to upload');
console.log('result type: ' + result.type);
console.log('result size: ' + result.size);
// this goes to dropzone on "sending" event
done(result);
},error: function (err) {
console.log(err.message);
},// end error
}); // end new Compressor
},// end transformFile
}); // end new Dropzone
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。