【小书签】Webp 图片一键回退到 PNG

这是一个充满后退意味的操作,但有时候我们确实会有这样的需求。这个小书签可以一键将页面中所有 webp 格式文件转换为 PNG,然后我们只需要从浏览器中将图片拖入文件夹,即可实现保存。这对于某些收集素材的操作是比较便捷的。

脚本本身的转换速度是比较快的,一般图片儿可以算是秒转。但某些页面下所包含的图片数量可能比较多,所以还是加了一个转换完成的弹出提示。

本脚本未做详尽测试,如有问题欢迎反馈,但不一定能够解决,因为受到一些安全设定的限制。另对在浏览器中打开的本地图片无效。

javascript:!function(){const imgs=[],replaceImg=imgs=>{if(!imgs.length)return void alert("Replace all!");const canvas=document.createElement("canvas"),ctx=canvas.getContext("2d");img=imgs.shift();const image=new Image;image.setAttribute("crossOrigin","anonymous"),image.onload=()=>{canvas.width=image.width,canvas.height=image.height,ctx.drawImage(image,0,0),img.src=canvas.toDataURL("image/png"),replaceImg(imgs)};const timestamp=(new Date).getTime();image.src=img.src+"?"+timestamp};document.body.querySelectorAll("img[src$=webp]").forEach(img=>imgs.push(img)),replaceImg(imgs)}();

我,老鼠,打钱!

AliPay-240 WePay-240 QQPay-240

Screenshot_1

Save-Image-as-Type
商店: Save image as Type - Chrome Web Store
官网: GitHub - cuixiping/Save-Image-as-Type: Chrome扩展:Save Image As Type,为图片右键菜单添加另存为jpg,png,webp文件的功能。Save Image as Type is an chrome extension which add Save as PNG / JPG / WebP option for the context menu of image.

1 个赞