首页 > 其他分享 >七牛云存储____js打水印加上传图片

七牛云存储____js打水印加上传图片

时间:2023-09-13 18:03:39浏览次数:37  
标签:function 七牛云 target text js ____ xhr context var


<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--  资源引用 -->
<script src="qnb64watermark/jquery-1.9.1.js"></script>
<script src="qnb64watermark/polyfill.js"></script>
<script src="qnb64watermark/watermark.js"></script>
<script src="qnb64watermark/highlight.min.js"></script>
<script src="qnb64watermark/tokenTools.js"></script>
<link rel="stylesheet" href="qnb64watermark/style.css">
<script type="text/javascript" src="qnb64watermark/jquery-ui.js"></script>
<link rel="stylesheet" type="text/css"	href="qnb64watermark/jquery-ui.css">


<script>hljs.initHighlightingOnLoad();</script>

</head>
<body>
 <img id="image"src=""/>
<br/>
 <input type="file" id="filename" />
 <input type="button" οnclick="selectImage();" value="上传ccccccccc">
<br/>
<script>
	var rotate = function(target) {
		  var context = target.getContext('2d');
		  var text = "www.水印.com";
		  var metrics = context.measureText(text);
		  var x = (target.width / 2) - (metrics.width + 12);
		  var y = (target.height / 2) + 48 * 2;
		  context.translate(x, y);
		  context.globalAlpha = 1.2;
		  context.fillStyle = '#FFFFFF';
		  context.font = '40px Josefin Slab';
		  context.rotate(-40 * Math.PI / 180);
		  context.fillText(text, 0, 0);
		  return target;
	};
	function selectImage() {
		var file=document.getElementById("filename");
		var reader = new FileReader();
		reader.onload = function(evt) {
			imagesrc = evt.target.result;
			var text = watermark.text;
			watermark([ imagesrc ]).image(rotate).then(function(img) {
				var imgsrc=img.src.replace("data:image/png;base64,", "");
			 	var b64key=base64encode(new Date().getTime()+".jpg");
				qnb64Upload(imgsrc,b64key);
				var pre = document.querySelector('#lower-left pre');
				pre.parentNode.insertBefore(img, pre);
			});
		};
		reader.readAsDataURL(file.files[0]);
	}
	function qnb64Upload(imgsrc,b64key){
		var pic = imgsrc;
	    var url = "http://up.qiniu.com/putb64/-1/key/"+b64key; 
		var xhr = new XMLHttpRequest();
		xhr.onreadystatechange = function(response) {
			if (xhr.readyState == 4 && xhr.status == 200&& xhr.responseText != "") {
				var blkRet = JSON.parse(xhr.responseText);
				$("#dialog").html("http://oleco2u3s.bkt.clouddn.com/" + blkRet.key).dialog();
			} else if (xhr.status != 200 && xhr.responseText) {
				console.log("服务传输异常!!");
			}
		};
		xhr.open("POST", url, true); 
		xhr.setRequestHeader("Content-Type", "application/octet-stream"); 
		xhr.setRequestHeader("Authorization", "UpToken 1o90vmY9OmRcueIeIeFBID6q2uy8peFiFBxpnM78:rdalpapK8yThJayH3FakQwqQbp8=:eyJzY29wZSI6InRlc3QiLCJkZWFkbGluZSI6MTYwNTA2NDI3MX0="); 
		xhr.send(pic);
	}		
</script>

  <div class="container">
    <div class="col-xs-12">
		<div class="example" id="lower-left">
	        <pre>          
	        	
	        </pre>
	    </div>
    </div>
    <div id="dialog" title="上传成功"></div>
  </div>
  
  
</body>
</html>
//源码包下载
http://oleco2u3s.bkt.clouddn.com/markupload.rar
//运行结果


七牛云存储____js打水印加上传图片_base64

标签:function,七牛云,target,text,js,____,xhr,context,var
From: https://blog.51cto.com/ratelcloud/7462899

相关文章

  • 七牛云存储____生成永久性token
    //MyHtml.html<!DOCTYPEhtml><html><head><title>MyHtml.html</title><metaname="keywords"content="keyword1,keyword2,keyword3"><metaname="description"content="thi......
  • 七牛云存储____七牛js直接上传图片
    <%@pagelanguage="java"import="java.util.*"pageEncoding="UTF-8"%><%Stringpath=request.getContextPath();StringbasePath=request.getScheme()+"://"+request.getServerName()+":"+request.getS......
  • 七牛云存储____官方SDK集成开发
    packagecom.scdn.qnscdn;/***七牛常理配置**@authorGod待整理好配到config文件里*ACCESSKEY这是我个人申请的一个测试的号everyonecanuseingit*SECRETKEY*/publicclassQnConstant{ //设置好账号的ACCESS_KEY和SECRET_KEY publicstaticfinalS......
  • 七牛云存储____图片转Base64串上传
    packagecom.scdn.qnscdn;/***七牛常理配置**@authorGod待整理好配到config文件里*ACCESSKEY这是我个人申请的一个测试的号everyonecanuseingit*SECRETKEY*/publicclassQnConstant{ //设置好账号的ACCESS_KEY和SECRET_KEY publicstaticfinalS......
  • 【ActiveMQ】Failed to start Apache ActiveMQ (localhost, ID_XXX)
    问题描述使用"bin\win64\activemq.bat"启动apache-activemq-5.18.2出错。jvm1|ERROR|FailedtostartApacheActiveMQ(localhost,ID:)jvm1|java.io.IOException:TransportConnectorcouldnotberegisteredinJMX:java.io.IOException:Failedtobin......
  • 通过 DevOps、CI/CD 和容器增强您的软件开发之旅...
    软件行业已经在DevOps、CI/CD和容器中找到了针对开发导向问题的有效解决方案。尽管并不强制要求将这三者一起使用,但它们通常是相互补充和依赖的。DevOps促进开发和IT团队之间的协作,而CI/CD简化软件交付流程以更快地获得结果。容器化将应用程序与其依赖项结合起来,以建立一致......
  • 2023国家网络安全宣传周|邮件安全意识培训-钓鱼篇
    干货满满建议收藏反复阅读钓鱼邮件钓鱼邮件是指黑客伪装成同事、合作伙伴、朋友、家人等用户信任的人,通过发送电子邮件的方式,诱使用户回复邮件、点击嵌入邮件正文的恶意链接或者打开邮件附件以植入木马或间谍程序,进而窃取用户敏感数据、个人银行账户和密码等信息,或者在设备上执......
  • TCP编程
    网络相关概念网络通信概念:两台设备之间通过网络实现数据传输。网络通信:将数据通过网络从一台设备传输到另一台设备中。java.net包下提供了一系列的类或接口,供程序员使用,完成网络通信。网络概念:两台或多台设备通过一定物理设备连接起来构成了网络。根据网络的覆盖范围不同,对网络进行......
  • 17-浮点数-自动转换-强制转换-增强赋值运算符
         ......
  • k8s笔记14
    摘要:多播路由守护程序;autogen;SMCRoute;pimd;mrouted;mcjointroglobit/pim6sd:PIMforIPv6sparsemodedaemon(github.com)Tip:为了安1、pim6sd自动将自身配置为在所有支持多播的接口interfaces(IFF_MULTICASTflag)上转发 forward,即设置了IFF_MULTICAST标志的接口(不包括excluding......