forked from Zecknol/lietxia.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makebg.htm
91 lines (81 loc) · 3.92 KB
/
makebg.htm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<!DOCTYPE html>
<html>
<head>
<title>雀魂桌布制作工具</title>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<style>
#bg {
display: none;
}
</style>
</head>
<body>
<label>图片长(像素)<input type="text" id="img_w" value="770" /></label><br />
<label>图片高(像素)<input type="text" id="img_h" value="770" /></label><br />
<label>距左侧(像素)<input type="text" id="img_x" value="115" /></label><br />
<label>距上侧(像素)<input type="text" id="img_y" value="115" /></label><br />
<label>变暗(0.2=加20%黑色)<input type="text" id="img_dark" value="0.2" /></label><br />
※游戏里有光照,背景会变亮(把背景图变暗可以中和变亮情况)<br />
<label>选择图片上传:
<input type="file" accept="image/*" id="imgup">
</label><br />
<input type="button" onclick="run()" value="图片合成"><br />
合成完,右键->保存[底部的图片]<br />
<input type="button" onclick="save()" value="或点此保存图片"><br />
<a id="link1" download="bg.png"></a>
再往 <a href="http://sm.ms">http://sm.ms</a> 传图片得到URL即可<br />
这个URL填到【重定向至:xxxx】
<hr />
<canvas id="myCanvas" width="1000" height="1000" style="border:1px solid #d3d3d3;">
请不要用那么老的浏览器!Your browser does not support the HTML5 canvas tag.
</canvas>
<img src="res/border.png" id="bg" />
<script>
window.maked = 0;
function save() {
if (window.maked === 0) { alert('请先合成图片'); return }
var Canvas = document.getElementById('myCanvas');
Canvas.crossOrigin = "Anonymous";
var link = document.getElementById('link1');
link.setAttribute('href', Canvas.toDataURL("image/png").replace("image/png", "image/octet-stream"));
link.click();
}
function run() {
let file = document.getElementById('imgup').files[0] // 获取选择的文件,这里是图片类型
if (typeof (file) == "undefined" || file.size <= 0) {
alert("请选择图片");
return;
}
let reader = new FileReader()
reader.readAsDataURL(file) //读取文件并将文件以URL的形式保存在resulr属性中 base64格式
reader.onload = function (e) { // 文件读取完成时触发
let result = e.target.result // base64格式图片地址
var image = new Image();
image.src = result // 设置image的地址为base64的地址
image.crossOrigin = "Anonymous";
image.onload = function () {
var Canvas = document.getElementById("myCanvas");
Canvas.crossOrigin = "Anonymous";
var cxt = Canvas.getContext("2d");
Canvas.height = 1001;
Canvas.height = 1000;
var bg = document.getElementById("bg");
bg.crossOrigin = "Anonymous";
var x = document.getElementById("img_x").value;
var y = document.getElementById("img_y").value;
var w = document.getElementById("img_w").value;
var h = document.getElementById("img_h").value;
cxt.drawImage(image, x, y, w, h) // 在canvas上绘制图片
var alpha = document.getElementById("img_dark").value;
alpha = Number(alpha).toFixed(2);
cxt.fillStyle = 'rgba(0, 0, 0, ' + alpha + ')';
cxt.fillRect(0, 0, 1000, 1000);
cxt.drawImage(bg, 0, 0, 1000, 1000);
window.maked = 1;
}
}
};
</script>
</body>
</html>