wasm-vips libvips webassembly 实现
  8KhYbgszLLmZ 2023年11月30日 24 0

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();

 

效果

原始图

wasm-vips libvips webassembly 实现_图片处理

生成图片

wasm-vips libvips webassembly 实现_图片处理_02

 

说明

以上是一个简单的使用,实际上也有基于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

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月30日 0

暂无评论

推荐阅读
8KhYbgszLLmZ