Pngtiny
一个js压缩图片的工具。功能用C编写,利用了libimagequant和libpng库,读取png图片进行压缩,然后导出wasm在页面运行,从而使得可以直接在页面压缩图片,不需要上传到服务器处理。
Install / Use
/learn @skyfish-qc/PngtinyREADME
#js版png压缩工具
- 2021.10.14 添加jpg图片压缩
- 2021.10.19 添加GIF图片压缩
- 2022.01.06 添加demo地址
##新加函数代码
unsigned char *
Gif_writeMem(Gif_Stream *gfs, const Gif_CompressInfo* gcinfo, unsigned long * outsize) {
Gif_Writer grr;
int ok = gif_writer_init(&grr, NULL, gcinfo)&& write_gif(gfs, &grr);
unsigned char* buf=NULL;
if(ok) {
buf = malloc(grr.pos);
memcpy(buf,grr.v, grr.pos);
memcpy(outsize,&grr.pos,sizeof(unsigned long));
}
gif_writer_cleanup(&grr);
return buf;
}
使用
部署web文件夹到服务器访问即可(需要在支持webassembly的浏览器访问,比如Chrome,edge)
可以访问 demo
说明
- 本项目使用了 https://github.com/ImageOptim/libimagequant , https://github.com/glennrp/libpng, https://github.com/kohler/gifsicle 以及 https://www.ijg.org/ 库
- libimagequant是png24压缩成png8的库,压缩效果很好。libpng是读取png以及生成png的库。libjpeg是读取以及压缩jpg的库。gifsicle是读取以及压缩gif的库。
- 如果需要编译自己的压缩代码,电脑环境先安装好新版的emsdk环境,然后运行build.bat文件即可。
- 然后把编译出来的pngtiny.js和pngtiny.wasm文件覆盖web文件夹里面的文件。
Related Skills
node-connect
339.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
83.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
339.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
83.8kCommit, push, and open a PR
