wasm-vips libvips webassembly 实现

wasm-vips 是利用了emscripten将libvips 编译为webassembly 可以实现在node 以及浏览器中使用libvips 强大的图片处理处理
以下是一个简单的试用

参考试用

  • app.js
 
const Vips = require('wasm-vips');
 
async function init() {
    const vips = await Vips();
    vips.Image.newFromFile('test.png')
    .smartcrop(320, 320,{
        interesting: vips.Interesting.attention
    }).writeToFile('test2.png');
 
    const thumbnail = vips.Image.thumbnail('test.png', 320, {
        height: 320,
        no_rotate: true,
        crop: vips.Interesting.attention // 'attention'
      });
      thumbnail.writeToFile('test3.png');
}
init();

效果

原始图

生成图片

 

说明

以上是一个简单的使用,实际上也有基于node 的包装sharp 是一个很不错的选择,但是基于webwaasmbly 也是一个不错的选择,至少不需要对于
libvips 的依赖了,sharp 是使用的预编译好的依赖

参考资料

https://github.com/kleisauke/wasm-vips
https://www.libvips.org/
https://github.com/libvips/libvips
https://emscripten.org/
https://github.com/lovell/sharp
https://github.com/emscripten-core/emscripten

posted on   荣锋亮  阅读(135)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2020-11-05 golang httpcache 一个方便的http cache 处理包
2020-11-05 httpcache4j 一个不错的httpcache 处理包
2019-11-05 go.rice 强大灵活的golang 静态资源嵌入包
2019-11-05 几个golang 静态资源嵌入包
2018-11-05 ballerina 学习二十九 数据库操作
2018-11-05 ballerina 学习二十八 快速grpc 服务开发
2018-11-05 ballerina 学习二十七 项目k8s部署&& 运行

导航

< 2025年3月 >
23 24 25 26 27 28 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 1 2 3 4 5
点击右上角即可分享
微信分享提示