From 03c14b4ab8a552efc24d0811b009ae498d24513a Mon Sep 17 00:00:00 2001 From: strawberry42271 <2806566736@qq.com> Date: Fri, 3 Jan 2025 16:35:46 +0800 Subject: [PATCH] =?UTF-8?q?webp=E5=AF=BC=E5=87=BA=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- project/plugins.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/project/plugins.js b/project/plugins.js index 3ab77f8..9503840 100644 --- a/project/plugins.js +++ b/project/plugins.js @@ -14433,5 +14433,24 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = console.log("The orientation API isn't supported in this browser :("); } } +}, + "图片压缩webp导出": function () { + // 在此增加新插件 + //使用方法:进入游戏后开始游戏,F12打开控制台,输入core.towebp(image),image为已在全塔属性中注册过的图片名字,需要""括起来 + this.towebp = function (image) { + const canvas = document.createElement('canvas'); //背景画布设置 + const ctx = canvas.getContext("2d") + const img = core.material.images.images[image] + canvas.width = img.width + canvas.height = img.height + ctx.drawImage(img, 0, 0) + const webpDataURL = canvas.toDataURL("image/webp", 1) //第二个参数为画面质量,范围为0-1,1为无损 + console.log(webpDataURL) + const link = document.createElement("a") + link.href = webpDataURL + const name = image.substring(0, image.indexOf(".")) + link.download = name + ".webp" + link.click() + } } } \ No newline at end of file