├── .gitattributes
├── .gitignore
├── README.md
├── code0.jpg
├── code1.jpg
├── gifmaker
├── .gitignore
├── .vscode
│ └── settings.json
├── Cargo.lock
├── Cargo.toml
├── build.cmd
├── build.rs
└── src
│ ├── gifmaker.rs
│ ├── js.rs
│ └── lib.rs
├── program
├── .gitignore
├── app.js
├── app.json
├── app.wxss
├── pages
│ ├── index
│ │ ├── index.js
│ │ ├── index.json
│ │ ├── index.wxml
│ │ └── index.wxss
│ └── logs
│ │ ├── logs.js
│ │ ├── logs.json
│ │ ├── logs.wxml
│ │ └── logs.wxss
├── project.config.json
├── project.private.config.json
├── sitemap.json
├── static
│ ├── album.png
│ ├── basicprofile.png
│ ├── camera.png
│ ├── campos.png
│ ├── code.jpg
│ ├── delete.png
│ ├── faceoff_logo.png
│ ├── ic_close.png
│ ├── ic_img.png
│ └── trash.png
└── utils
│ ├── encoding.js
│ ├── gifmaker
│ ├── gifmaker.js
│ └── gifmaker_bg.wasm
│ ├── img_sec_check.js
│ └── util.js
├── screenrecorder.gif
├── screenshot.jpg
└── server
├── README.md
├── server_utc_now
├── .cargo
│ └── config.toml
├── .gitignore
├── Cargo.toml
├── build-run.cmd
├── run.cmd
├── spin.toml
└── src
│ └── lib.rs
└── wx_sec_check
├── .cargo
└── config.toml
├── .gitignore
├── Cargo.toml
├── build-run.cmd
├── run.cmd
├── spin.toml
├── src
├── lib.rs
├── sec_check.rs
├── secret.rs
├── token.rs
└── tools.rs
└── test_client
├── .gitignore
├── Cargo.toml
├── src
└── main.rs
└── test.png
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /.history
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # miniprogram-gifmaker
2 |
3 | GIF动画制作微信小程序
4 |
5 | ## 目录结构
6 |
7 | /gifmaker 生成GIF的Rust库,编译为Webassembly
8 |
9 | /program 微信小程序代码
10 |
11 | /server 图像审查服务器端代码
12 |
13 | ## 运行截图
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/code0.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/planet0104/miniprogram-gifmaker/cf6e8702d24dec9ba15552073d06ff0467a5a456/code0.jpg
--------------------------------------------------------------------------------
/code1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/planet0104/miniprogram-gifmaker/cf6e8702d24dec9ba15552073d06ff0467a5a456/code1.jpg
--------------------------------------------------------------------------------
/gifmaker/.gitignore:
--------------------------------------------------------------------------------
1 | /.history
2 | /target
3 | **/*.rs.bk
4 | /pkg
5 | /gm_check_code.rs
--------------------------------------------------------------------------------
/gifmaker/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "rust-analyzer.cargo.target": "wasm32-unknown-unknown",
3 | }
--------------------------------------------------------------------------------
/gifmaker/Cargo.lock:
--------------------------------------------------------------------------------
1 | # This file is automatically @generated by Cargo.
2 | # It is not intended for manual editing.
3 | version = 3
4 |
5 | [[package]]
6 | name = "adler"
7 | version = "1.0.2"
8 | source = "registry+https://github.com/rust-lang/crates.io-index"
9 | checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
10 |
11 | [[package]]
12 | name = "adler32"
13 | version = "1.2.0"
14 | source = "registry+https://github.com/rust-lang/crates.io-index"
15 | checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234"
16 |
17 | [[package]]
18 | name = "aes"
19 | version = "0.7.5"
20 | source = "registry+https://github.com/rust-lang/crates.io-index"
21 | checksum = "9e8b47f52ea9bae42228d07ec09eb676433d7c4ed1ebdf0f1d1c29ed446f1ab8"
22 | dependencies = [
23 | "cfg-if 1.0.0",
24 | "cipher",
25 | "cpufeatures",
26 | "opaque-debug",
27 | ]
28 |
29 | [[package]]
30 | name = "anyhow"
31 | version = "1.0.55"
32 | source = "registry+https://github.com/rust-lang/crates.io-index"
33 | checksum = "159bb86af3a200e19a068f4224eae4c8bb2d0fa054c7e5d1cacd5cef95e684cd"
34 |
35 | [[package]]
36 | name = "base64"
37 | version = "0.13.0"
38 | source = "registry+https://github.com/rust-lang/crates.io-index"
39 | checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
40 |
41 | [[package]]
42 | name = "base64"
43 | version = "0.20.0-alpha.1"
44 | source = "registry+https://github.com/rust-lang/crates.io-index"
45 | checksum = "149ea5dc24cb11513350770afebba32b68e3d2e356f9221351a2a1ee89112a82"
46 |
47 | [[package]]
48 | name = "bitflags"
49 | version = "1.0.4"
50 | source = "registry+https://github.com/rust-lang/crates.io-index"
51 | checksum = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12"
52 |
53 | [[package]]
54 | name = "block-buffer"
55 | version = "0.9.0"
56 | source = "registry+https://github.com/rust-lang/crates.io-index"
57 | checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4"
58 | dependencies = [
59 | "block-padding",
60 | "generic-array",
61 | ]
62 |
63 | [[package]]
64 | name = "block-modes"
65 | version = "0.8.1"
66 | source = "registry+https://github.com/rust-lang/crates.io-index"
67 | checksum = "2cb03d1bed155d89dce0f845b7899b18a9a163e148fd004e1c28421a783e2d8e"
68 | dependencies = [
69 | "block-padding",
70 | "cipher",
71 | ]
72 |
73 | [[package]]
74 | name = "block-padding"
75 | version = "0.2.1"
76 | source = "registry+https://github.com/rust-lang/crates.io-index"
77 | checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae"
78 |
79 | [[package]]
80 | name = "bumpalo"
81 | version = "3.9.1"
82 | source = "registry+https://github.com/rust-lang/crates.io-index"
83 | checksum = "a4a45a46ab1f2412e53d3a0ade76ffad2025804294569aae387231a0cd6e0899"
84 |
85 | [[package]]
86 | name = "byteorder"
87 | version = "1.4.3"
88 | source = "registry+https://github.com/rust-lang/crates.io-index"
89 | checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
90 |
91 | [[package]]
92 | name = "cfg-if"
93 | version = "0.1.10"
94 | source = "registry+https://github.com/rust-lang/crates.io-index"
95 | checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
96 |
97 | [[package]]
98 | name = "cfg-if"
99 | version = "1.0.0"
100 | source = "registry+https://github.com/rust-lang/crates.io-index"
101 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
102 |
103 | [[package]]
104 | name = "cipher"
105 | version = "0.3.0"
106 | source = "registry+https://github.com/rust-lang/crates.io-index"
107 | checksum = "7ee52072ec15386f770805afd189a01c8841be8696bed250fa2f13c4c0d6dfb7"
108 | dependencies = [
109 | "generic-array",
110 | ]
111 |
112 | [[package]]
113 | name = "color_quant"
114 | version = "1.0.1"
115 | source = "registry+https://github.com/rust-lang/crates.io-index"
116 | checksum = "0dbbb57365263e881e805dc77d94697c9118fd94d8da011240555aa7b23445bd"
117 |
118 | [[package]]
119 | name = "cpufeatures"
120 | version = "0.2.2"
121 | source = "registry+https://github.com/rust-lang/crates.io-index"
122 | checksum = "59a6001667ab124aebae2a495118e11d30984c3a653e99d86d58971708cf5e4b"
123 | dependencies = [
124 | "libc",
125 | ]
126 |
127 | [[package]]
128 | name = "crc-any"
129 | version = "2.4.3"
130 | source = "registry+https://github.com/rust-lang/crates.io-index"
131 | checksum = "774646b687f63643eb0f4bf13dc263cb581c8c9e57973b6ddf78bda3994d88df"
132 | dependencies = [
133 | "debug-helper",
134 | ]
135 |
136 | [[package]]
137 | name = "crc32fast"
138 | version = "1.2.0"
139 | source = "registry+https://github.com/rust-lang/crates.io-index"
140 | checksum = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1"
141 | dependencies = [
142 | "cfg-if 0.1.10",
143 | ]
144 |
145 | [[package]]
146 | name = "debug-helper"
147 | version = "0.3.13"
148 | source = "registry+https://github.com/rust-lang/crates.io-index"
149 | checksum = "f578e8e2c440e7297e008bb5486a3a8a194775224bbc23729b0dbdfaeebf162e"
150 |
151 | [[package]]
152 | name = "deflate"
153 | version = "1.0.0"
154 | source = "registry+https://github.com/rust-lang/crates.io-index"
155 | checksum = "c86f7e25f518f4b81808a2cf1c50996a61f5c2eb394b2393bd87f2a4780a432f"
156 | dependencies = [
157 | "adler32",
158 | ]
159 |
160 | [[package]]
161 | name = "des"
162 | version = "0.7.0"
163 | source = "registry+https://github.com/rust-lang/crates.io-index"
164 | checksum = "ac41dd49fb554432020d52c875fc290e110113f864c6b1b525cd62c7e7747a5d"
165 | dependencies = [
166 | "byteorder",
167 | "cipher",
168 | "opaque-debug",
169 | ]
170 |
171 | [[package]]
172 | name = "digest"
173 | version = "0.9.0"
174 | source = "registry+https://github.com/rust-lang/crates.io-index"
175 | checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066"
176 | dependencies = [
177 | "generic-array",
178 | ]
179 |
180 | [[package]]
181 | name = "generic-array"
182 | version = "0.14.5"
183 | source = "registry+https://github.com/rust-lang/crates.io-index"
184 | checksum = "fd48d33ec7f05fbfa152300fdad764757cbded343c1aa1cff2fbaf4134851803"
185 | dependencies = [
186 | "typenum",
187 | "version_check",
188 | ]
189 |
190 | [[package]]
191 | name = "gif"
192 | version = "0.11.3"
193 | source = "registry+https://github.com/rust-lang/crates.io-index"
194 | checksum = "c3a7187e78088aead22ceedeee99779455b23fc231fe13ec443f99bb71694e5b"
195 | dependencies = [
196 | "color_quant",
197 | "weezl",
198 | ]
199 |
200 | [[package]]
201 | name = "gifmaker"
202 | version = "1.0.3"
203 | dependencies = [
204 | "anyhow",
205 | "base64 0.20.0-alpha.1",
206 | "gif",
207 | "js-sys",
208 | "magic-crypt",
209 | "once_cell",
210 | "png",
211 | "wasm-bindgen",
212 | "web-sys",
213 | ]
214 |
215 | [[package]]
216 | name = "js-sys"
217 | version = "0.3.57"
218 | source = "registry+https://github.com/rust-lang/crates.io-index"
219 | checksum = "671a26f820db17c2a2750743f1dd03bafd15b98c9f30c7c2628c024c05d73397"
220 | dependencies = [
221 | "wasm-bindgen",
222 | ]
223 |
224 | [[package]]
225 | name = "lazy_static"
226 | version = "1.4.0"
227 | source = "registry+https://github.com/rust-lang/crates.io-index"
228 | checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
229 |
230 | [[package]]
231 | name = "libc"
232 | version = "0.2.126"
233 | source = "registry+https://github.com/rust-lang/crates.io-index"
234 | checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836"
235 |
236 | [[package]]
237 | name = "log"
238 | version = "0.4.14"
239 | source = "registry+https://github.com/rust-lang/crates.io-index"
240 | checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
241 | dependencies = [
242 | "cfg-if 1.0.0",
243 | ]
244 |
245 | [[package]]
246 | name = "magic-crypt"
247 | version = "3.1.10"
248 | source = "registry+https://github.com/rust-lang/crates.io-index"
249 | checksum = "6c913782c21b53ad246863641fffbaf73a9eb32ff0d939b10d361b7294e2ea9c"
250 | dependencies = [
251 | "aes",
252 | "base64 0.13.0",
253 | "block-modes",
254 | "crc-any",
255 | "des",
256 | "digest",
257 | "md-5",
258 | "sha2",
259 | "tiger",
260 | ]
261 |
262 | [[package]]
263 | name = "md-5"
264 | version = "0.9.1"
265 | source = "registry+https://github.com/rust-lang/crates.io-index"
266 | checksum = "7b5a279bb9607f9f53c22d496eade00d138d1bdcccd07d74650387cf94942a15"
267 | dependencies = [
268 | "block-buffer",
269 | "digest",
270 | "opaque-debug",
271 | ]
272 |
273 | [[package]]
274 | name = "miniz_oxide"
275 | version = "0.5.1"
276 | source = "registry+https://github.com/rust-lang/crates.io-index"
277 | checksum = "d2b29bd4bc3f33391105ebee3589c19197c4271e3e5a9ec9bfe8127eeff8f082"
278 | dependencies = [
279 | "adler",
280 | ]
281 |
282 | [[package]]
283 | name = "once_cell"
284 | version = "1.12.0"
285 | source = "registry+https://github.com/rust-lang/crates.io-index"
286 | checksum = "7709cef83f0c1f58f666e746a08b21e0085f7440fa6a29cc194d68aac97a4225"
287 |
288 | [[package]]
289 | name = "opaque-debug"
290 | version = "0.3.0"
291 | source = "registry+https://github.com/rust-lang/crates.io-index"
292 | checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
293 |
294 | [[package]]
295 | name = "png"
296 | version = "0.17.5"
297 | source = "registry+https://github.com/rust-lang/crates.io-index"
298 | checksum = "dc38c0ad57efb786dd57b9864e5b18bae478c00c824dc55a38bbc9da95dde3ba"
299 | dependencies = [
300 | "bitflags",
301 | "crc32fast",
302 | "deflate",
303 | "miniz_oxide",
304 | ]
305 |
306 | [[package]]
307 | name = "proc-macro2"
308 | version = "1.0.36"
309 | source = "registry+https://github.com/rust-lang/crates.io-index"
310 | checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029"
311 | dependencies = [
312 | "unicode-xid",
313 | ]
314 |
315 | [[package]]
316 | name = "quote"
317 | version = "1.0.15"
318 | source = "registry+https://github.com/rust-lang/crates.io-index"
319 | checksum = "864d3e96a899863136fc6e99f3d7cae289dafe43bf2c5ac19b70df7210c0a145"
320 | dependencies = [
321 | "proc-macro2",
322 | ]
323 |
324 | [[package]]
325 | name = "sha2"
326 | version = "0.9.9"
327 | source = "registry+https://github.com/rust-lang/crates.io-index"
328 | checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800"
329 | dependencies = [
330 | "block-buffer",
331 | "cfg-if 1.0.0",
332 | "cpufeatures",
333 | "digest",
334 | "opaque-debug",
335 | ]
336 |
337 | [[package]]
338 | name = "syn"
339 | version = "1.0.86"
340 | source = "registry+https://github.com/rust-lang/crates.io-index"
341 | checksum = "8a65b3f4ffa0092e9887669db0eae07941f023991ab58ea44da8fe8e2d511c6b"
342 | dependencies = [
343 | "proc-macro2",
344 | "quote",
345 | "unicode-xid",
346 | ]
347 |
348 | [[package]]
349 | name = "tiger"
350 | version = "0.1.0"
351 | source = "registry+https://github.com/rust-lang/crates.io-index"
352 | checksum = "443e531cbcf9de83258cfef70bcd56c91188de5819ebd4b19c85f589e0617005"
353 | dependencies = [
354 | "block-buffer",
355 | "byteorder",
356 | "digest",
357 | ]
358 |
359 | [[package]]
360 | name = "typenum"
361 | version = "1.15.0"
362 | source = "registry+https://github.com/rust-lang/crates.io-index"
363 | checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987"
364 |
365 | [[package]]
366 | name = "unicode-xid"
367 | version = "0.2.2"
368 | source = "registry+https://github.com/rust-lang/crates.io-index"
369 | checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
370 |
371 | [[package]]
372 | name = "version_check"
373 | version = "0.9.4"
374 | source = "registry+https://github.com/rust-lang/crates.io-index"
375 | checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
376 |
377 | [[package]]
378 | name = "wasm-bindgen"
379 | version = "0.2.80"
380 | source = "registry+https://github.com/rust-lang/crates.io-index"
381 | checksum = "27370197c907c55e3f1a9fbe26f44e937fe6451368324e009cba39e139dc08ad"
382 | dependencies = [
383 | "cfg-if 1.0.0",
384 | "wasm-bindgen-macro",
385 | ]
386 |
387 | [[package]]
388 | name = "wasm-bindgen-backend"
389 | version = "0.2.80"
390 | source = "registry+https://github.com/rust-lang/crates.io-index"
391 | checksum = "53e04185bfa3a779273da532f5025e33398409573f348985af9a1cbf3774d3f4"
392 | dependencies = [
393 | "bumpalo",
394 | "lazy_static",
395 | "log",
396 | "proc-macro2",
397 | "quote",
398 | "syn",
399 | "wasm-bindgen-shared",
400 | ]
401 |
402 | [[package]]
403 | name = "wasm-bindgen-macro"
404 | version = "0.2.80"
405 | source = "registry+https://github.com/rust-lang/crates.io-index"
406 | checksum = "17cae7ff784d7e83a2fe7611cfe766ecf034111b49deb850a3dc7699c08251f5"
407 | dependencies = [
408 | "quote",
409 | "wasm-bindgen-macro-support",
410 | ]
411 |
412 | [[package]]
413 | name = "wasm-bindgen-macro-support"
414 | version = "0.2.80"
415 | source = "registry+https://github.com/rust-lang/crates.io-index"
416 | checksum = "99ec0dc7a4756fffc231aab1b9f2f578d23cd391390ab27f952ae0c9b3ece20b"
417 | dependencies = [
418 | "proc-macro2",
419 | "quote",
420 | "syn",
421 | "wasm-bindgen-backend",
422 | "wasm-bindgen-shared",
423 | ]
424 |
425 | [[package]]
426 | name = "wasm-bindgen-shared"
427 | version = "0.2.80"
428 | source = "registry+https://github.com/rust-lang/crates.io-index"
429 | checksum = "d554b7f530dee5964d9a9468d95c1f8b8acae4f282807e7d27d4b03099a46744"
430 |
431 | [[package]]
432 | name = "web-sys"
433 | version = "0.3.57"
434 | source = "registry+https://github.com/rust-lang/crates.io-index"
435 | checksum = "7b17e741662c70c8bd24ac5c5b18de314a2c26c32bf8346ee1e6f53de919c283"
436 | dependencies = [
437 | "js-sys",
438 | "wasm-bindgen",
439 | ]
440 |
441 | [[package]]
442 | name = "weezl"
443 | version = "0.1.5"
444 | source = "registry+https://github.com/rust-lang/crates.io-index"
445 | checksum = "d8b77fdfd5a253be4ab714e4ffa3c49caf146b4de743e97510c0656cf90f1e8e"
446 |
--------------------------------------------------------------------------------
/gifmaker/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "gifmaker"
3 | version = "1.0.3"
4 | authors = ["Jia Ye "]
5 | edition = "2021"
6 |
7 | [lib]
8 | crate-type = ["cdylib"]
9 |
10 | [dependencies]
11 | wasm-bindgen = "0.2.80"
12 | js-sys = "0.3.57"
13 | gif = "0.11.3"
14 | png = "0.17.5"
15 | once_cell = "1.12"
16 | anyhow = "1"
17 | base64 = "0.20.0-alpha.1"
18 | magic-crypt = "3.1.10"
19 |
20 | [dependencies.web-sys]
21 | version = "0.3.57"
22 | features = [
23 | 'Document',
24 | 'Window',
25 | ]
26 |
27 | [profile.release]
28 | lto = true
29 | opt-level = 'z'
30 | codegen-units = 1
31 | panic = 'abort'
--------------------------------------------------------------------------------
/gifmaker/build.cmd:
--------------------------------------------------------------------------------
1 | :: Compile our wasm module and run `wasm-bindgen`
2 | wasm-pack build --target web
--------------------------------------------------------------------------------
/gifmaker/build.rs:
--------------------------------------------------------------------------------
1 | use std::{fs::File, io::Write};
2 |
3 | fn main(){
4 | let mut file = File::create("gm_check_code.rs").unwrap();
5 | file.write_all(env!("gm_check_code").as_bytes()).unwrap();
6 | }
--------------------------------------------------------------------------------
/gifmaker/src/gifmaker.rs:
--------------------------------------------------------------------------------
1 | use std::sync::{Arc, Mutex};
2 | use std::io::{self, Write, IoSlice};
3 | use anyhow::{anyhow, Result};
4 | use gif::*;
5 | use crate::js::*;
6 |
7 | struct MyData{
8 | data: Arc>>,
9 | }
10 |
11 | impl Clone for MyData{
12 | fn clone(&self) -> Self {
13 | MyData{
14 | data: self.data.clone()
15 | }
16 | }
17 | }
18 |
19 | impl Write for MyData{
20 | #[inline]
21 | fn write(&mut self, buf: &[u8]) -> io::Result {
22 | self.data.lock().unwrap().extend_from_slice(buf);
23 | Ok(buf.len())
24 | }
25 |
26 | #[inline]
27 | fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result {
28 | let len = bufs.iter().map(|b| b.len()).sum();
29 | let mut _self = self.data.lock().unwrap();
30 | _self.reserve(len);
31 | for buf in bufs {
32 | _self.extend_from_slice(buf);
33 | }
34 | Ok(len)
35 | }
36 |
37 | #[inline]
38 | fn flush(&mut self) -> io::Result<()> {
39 | Ok(())
40 | }
41 | }
42 |
43 | pub struct GifMaker{
44 | //最终生成的文件数据
45 | data: MyData,
46 | // Encoder
47 | encoder: Encoder,
48 | fps: u16,
49 | width: u16,
50 | height: u16,
51 | }
52 |
53 | impl GifMaker{
54 | pub fn new(width: u16, height: u16, fps: u16) -> Result{
55 | log(&format!("GifMaker new: width={} height={} fps={}", width, height, fps));
56 | let data = MyData{data: Arc::new(Mutex::new(vec![])) };
57 | let mut encoder = Encoder::new(data.clone(), width, height, &[])?;
58 | encoder.set_repeat(Repeat::Infinite)?;
59 | Ok(GifMaker{
60 | data,
61 | encoder,
62 | fps,
63 | width,
64 | height
65 | })
66 | }
67 |
68 | // pub fn get_width(&self) -> u16{
69 | // self.width
70 | // }
71 |
72 | // pub fn get_height(&self) -> u16{
73 | // self.height
74 | // }
75 |
76 | pub fn add_png(&mut self, file:&[u8]) -> Result<()>{
77 | let decoder = png::Decoder::new(file);
78 | let mut reader = decoder.read_info()?;
79 | let mut buf = vec![0; reader.output_buffer_size()];
80 | reader.next_frame(&mut buf)?;
81 | let mut frame = gif::Frame::from_rgba_speed(self.width, self.height, &mut buf, 30);
82 | frame.delay = 1000 / self.fps / 10; //设置帧率 10ms倍数
83 | self.encoder.write_frame(&frame)?;
84 |
85 | Ok(())
86 | }
87 |
88 | pub fn get_file(&mut self) -> Result>{
89 | match self.data.data.lock(){
90 | Ok(data) => Ok(data.clone()),
91 | Err(err) => Err(anyhow!("{:?}", err))
92 | }
93 | }
94 | }
--------------------------------------------------------------------------------
/gifmaker/src/js.rs:
--------------------------------------------------------------------------------
1 | use js_sys::Object;
2 | use wasm_bindgen::prelude::*;
3 |
4 | #[wasm_bindgen]
5 | extern "C" {
6 | #[wasm_bindgen(js_namespace = console)]
7 | pub fn log(s: &str);
8 | #[wasm_bindgen(js_namespace = console)]
9 | pub fn error(s: &str);
10 | #[wasm_bindgen(js_namespace = wx)]
11 | pub fn showModal(param: &Object);
12 | #[wasm_bindgen(js_namespace = wx)]
13 | pub fn getAccountInfoSync() -> Object;
14 | }
15 |
--------------------------------------------------------------------------------
/gifmaker/src/lib.rs:
--------------------------------------------------------------------------------
1 | use std::{sync::{Mutex, MutexGuard}};
2 | use js_sys::*;
3 | use magic_crypt::{new_magic_crypt, MagicCryptTrait};
4 | use once_cell::sync::Lazy;
5 | use wasm_bindgen::prelude::*;
6 | mod js;
7 | mod gifmaker;
8 | use js::*;
9 | use gifmaker::*;
10 |
11 | static GIFMAKER: Lazy>> = Lazy::new(|| {
12 | Mutex::new(None)
13 | });
14 |
15 | fn lock() -> Result>, wasm_bindgen::JsValue>{
16 | match GIFMAKER.lock(){
17 | Ok(gifmaker) => {
18 | Ok(gifmaker)
19 | }
20 | Err(err) => Err(JsValue::from(format!("{:?}", err)))
21 | }
22 | }
23 |
24 | /// 初始化Gif编码器
25 | #[wasm_bindgen(js_name = create)]
26 | pub fn create(width: u16, height: u16, fps: u16) -> Result<(), JsValue>{
27 | log("开始创建Gifmaker");
28 | let mut gifmaker = lock()?;
29 | match GifMaker::new(width, height, fps){
30 | Ok(mk) => {
31 | gifmaker.replace(mk);
32 | log("Gifmaker创建完成");
33 | Ok(())
34 | }
35 | Err(err) => Err(JsValue::from(format!("{:?}", err))),
36 | }
37 | }
38 |
39 | /// 添加图片(png文件)
40 | #[wasm_bindgen(js_name = addPng)]
41 | pub fn add_png(src: Uint8ClampedArray) -> Result<(), JsValue>{
42 | let mut gifmaker = lock()?;
43 | match gifmaker.as_mut(){
44 | Some(gifmaker) => {
45 | if let Err(err) = gifmaker.add_png(&src.to_vec()){
46 | Err(JsValue::from(format!("{:?}", err)))
47 | }else{
48 | Ok(())
49 | }
50 | }
51 | None => Err(JsValue::from("请先创建GifMaker"))
52 | }
53 | }
54 |
55 | /// 生成gif
56 | #[wasm_bindgen(js_name = getFile)]
57 | pub fn get_file() -> Result{
58 | let mut gifmaker = lock()?;
59 | match gifmaker.as_mut(){
60 | Some(gifmaker) => {
61 | match gifmaker.get_file(){
62 | Ok(file) => {
63 | let arr = Uint8ClampedArray::new_with_length(file.len() as u32);
64 | arr.copy_from(&file);
65 | Ok(arr)
66 | }
67 | Err(err) => Err(JsValue::from(format!("{:?}", err)))
68 | }
69 | }
70 | None => Err(JsValue::from("请先创建GifMaker"))
71 | }
72 | }
73 |
74 | const SECRET_KEY: &str = env!("gm_secret_key");
75 | const SECRET_IV: &str = env!("gm_secret_iv");
76 | pub const APPID: &str = env!("gm_app_id");
77 |
78 | /// 生成验证API网关的密钥Header
79 | #[wasm_bindgen(js_name = generateHeaders)]
80 | pub fn generate_headers(mut timestamp: f64) -> Result