-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjapanese.html
More file actions
222 lines (197 loc) · 6.67 KB
/
japanese.html
File metadata and controls
222 lines (197 loc) · 6.67 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>データ</title>
<style>
body {
background-color: #333333;
color: #f6f6f6;
word-wrap: break-word;
}
.container {
width: 95%;
height: auto;
margin: 7px auto;
background-color: rgba(100, 100, 100, 0.5);
padding: 4px;
}
h3 {
margin: 5px;
}
h4 {
margin: 5px;
}
.author {
text-align: center;
margin: 2px auto;
color: #aeaeae;
}
a {
color: skyblue;
}
button {
border: none;
background-color: rgba(110, 110, 110, 1.0);
color: #f6f6f6;
padding: 2px 7px 2px 7px;
font-size: 13px;
}
.line {
width: auto;
margin: auto auto auto 2%;
}
</style>
</head>
<body>
<a href="index.html">English</a>
<a href="t-chinese.html">繁體中文</a>
<a href="chinese.html">简体中文</a>
<a href="french.html">Français</a>
<a href="german.html">Deutsch</a>
<div class="container">
<h3>画像導入</h3>
<div class="container">
<input type="file" id="input" name="image" accept=".jpg,.jpeg,.png,.PNG,.JPG,.JPEG">
<button id="loadButton">導入</button>
<div id="submitNotification"></div>
</div>
</div>
<div class="container">
<h3>画像処理</h3>
<div class="line">
<div>ズーム倍率</div>
<input style="width: 100px;" type="number" id="zoomScale" min="0" max="10" value=1 placeholder="0~10">
<button id="submitButton">確定</button>
</div>
<div><br><br></div>
<div id="fileInfo" style="width = auto; margin: auto auto auto 2%;"></div>
<div class="line">プレビュー:</div>
<canvas style="margin: auto auto auto 2%;" id="imagePreview"></canvas>
</div>
<div class="container">
<h3>データ</h3>
<button style="margin: auto 2px auto 2%;" id="startButton">生成データ</button>
<button style="margin: auto auto auto 2px;" id="copyButton">コピー</button>
<div class="container">
<div>プレビュー:</div>
<div id="dataPreview" style="font-family: monospace, Courier, sans-serif;">-</div>
</div>
</div>
<div class="author">Made by <a href="https://b23.tv/eWskduP">Sioneo</a>(Bilibili)/<a href="https://forum.theotown.com/memberlist.php?mode=viewprofile&u=227382">dnswodn</a>(Forum)</div>
<script>
const imageInput = document.getElementById("input");
const fileInfo = document.getElementById("fileInfo");
const dataPreview = document.getElementById("dataPreview");
const submitButton = document.getElementById("submitButton");
const submitNotification = document.getElementById("submitNotification");
const imagePreviewCanvas = document.getElementById("imagePreview");
const copyButton = document.getElementById("copyButton");
const image = new Image();
let zoomScale = document.getElementById("zoomScale").value;
let hasLoadedImage;
let imagePreviewCanvasCtx;
let dataOutput = "";
// 绘制图片
function drawImageCanvas(){
imagePreviewCanvas.width = image.width * zoomScale;
imagePreviewCanvas.height = image.height * zoomScale;
imagePreviewCanvasCtx = imagePreviewCanvas.getContext("2d");
imagePreviewCanvasCtx.drawImage(image, 0, 0, imagePreviewCanvas.width, imagePreviewCanvas.height);
fileInfo.textContent = "画像サイズ:" + imagePreviewCanvas.width.toString() + "*" + imagePreviewCanvas.height.toString();
}
// 复制按钮监听器
copyButton.addEventListener("click", async () => {
const text = dataPreview.textContent;
try{
await navigator.clipboard.writeText(text);
dataPreview.textContent = "コピー成功";
}
catch(err){
dataPreview.textContent = "コピー失敗";
}
function changeTextBack(){
dataPreview.textContent = text;
}
setTimeout(changeTextBack, 2500);
});
// 添加开始生成按钮监听器
startButton.addEventListener("click", function(){
if (!hasLoadedImage){
dataPreview.textContent = "画像をロードしてください";
}
else{
dataPreview.textContent = "生成中…";
dataOutput = "data = {"; // 开始
for (let y = 0; y < imagePreviewCanvas.height; y++){
if (y != 0){
dataOutput += ",";
}
dataOutput += "{"; // 本行开始
for (let x = 0; x < imagePreviewCanvas.width; x++){
let pixelSource = imagePreviewCanvasCtx.getImageData(x, y, 1, 1);
let pixelData = pixelSource.data;
let red = pixelData[0];
let green = pixelData[1];
let blue = pixelData[2];
let alpha = pixelData[3];
if (x != 0 && x != imagePreviewCanvas.width){
dataOutput += ",";
}
let pixelColor;
// 如果不为完全透明则输出RGB值
if (alpha > 0){
pixelColor = "{" + red + "," + green + "," + blue + "}";
}
// 否则输出0表示透明
else{
pixelColor = "0";
}
dataOutput += pixelColor;
}
dataOutput += "}"; // 本行结束
}
dataOutput += "}"; // 结束
dataPreview.textContent = dataOutput;
}
});
// 添加确定缩放倍率按钮监听器
submitButton.addEventListener("click", function(){
zoomScale = document.getElementById("zoomScale").value;
drawImageCanvas(); // 刷新图片
dataOutput = ""; // 清空数据
dataPreview.textContent = dataOutput;
});
// 添加导入按钮按下监听器
loadButton.addEventListener("click", function(){
const file = imageInput.files[0];
if (file == null){
submitNotification.textContent = "まず画像ファイルを一つ選んでください";
}
else{
submitNotification.textContent = "成功";
hasLoadedImage = true;
image.onload = function(){
fileInfo.textContent = "画像ファイルを処理中です……";
drawImageCanvas();
}
image.oneerror = function(){
fileInfo.textContent = "エラー";
}
// 添加文件阅读器
const reader = new FileReader();
reader.onload = function(e) {
image.src = e.target.result;
};
reader.readAsDataURL(file);
function changeTextBack(){
submitNotification.textContent = "";
}
setTimeout(changeTextBack, 2500);
}
dataOutput = ""; // 清空数据
dataPreview.textContent = dataOutput;
});
</script>
</body>
</html>