New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

image-wasm-for-war3

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

image-wasm-for-war3

image process by wasm

  • 2.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9
decreased by-10%
Maintainers
1
Weekly downloads
 
Created
Source

简介

image-wasm-for-war3 是一个使用 WebAssembly 技术实现的图像处理库,可以在浏览器和 Node.js 环境中使用。该库提供了一组 API,用于对 RGBA 的图像数据进行解码和编码

安装

您可以使用 npm 包管理器来安装 image-wasm-for-war3:

npm install image-wasm-for-war3

使用

encode

const fs = require("fs");
const { ImageType, encode } = require("image-wasm-for-war3");

const data = new Uint8Array(
  new Array(100 * 100 * 4).fill(0).map((_, i) => i % 255)
);
const image = {
    width: 100,
    height: 100,
    buffer: data.buffer,
}

encode(image, ImageType.Tga).then((tgaContent) => {
  fs.writeFileSync("test.tga", Buffer.from(tgaContent));
});

encode(image, ImageType.Blp1).then((blp1Content) => {
  fs.writeFileSync("test.blp", Buffer.from(blp1Content));
});

decode

const fs = require("fs");
const { ImageType, decode } = require("image-wasm-for-war3");

decode(fs.readFileSync('test.tga'), ImageType.Tga).then((rgbaData) => {
    console.info(rgbaData.width);
    console.info(rgbaData.height);
    console.info(rgbaData.buffer);
});

decode(fs.readFileSync('test.blp'), ImageType.Blp1).then((rgbaData) => {
    console.info(rgbaData.width);
    console.info(rgbaData.height);
    console.info(rgbaData.buffer);
});

resize

const fs = require("fs");
const { ImageType, encode, decode, resize } = require("image-wasm-for-war3");

decode(fs.readFileSync('big.tga'), ImageType.Tga)
  .then((rgbaData) => resize(rgbaData, 50, 50))
  .then(resizeImage => encode(resizeImage, ImageType.Tga))
  .then((tgaContent) => {
    fs.writeFileSync("small.tga", Buffer.from(tgaContent));
  });

blp1的处理

const fs = require("fs");
const { Blp1File, encode, decode, ImageType } = require("image-wasm-for-war3");

const resizeImage = await decode(fs.readFileSync('some jpeg path'), ImageType.Jpeg);
// 生成一个 mimap是一个 质量是80 的blp1文件
const blpContent = await Blp1File.encode(resizeImage).encode(80, 1);
// 保存文件
fs.writeFileSync('some blp path', Buffer.from(blpContent));

// 获取blp的第一张mimap数据
const blpImageData = await Blp1File.decode(fs.readFileSync('some blp path')).getMimapData(0);
// 编码成png
const pngContent = await encode(blpImageData, ImageType.Png);
// 保存成png
fs.writeFileSync('some png path', Buffer.from(pngContent));

构建

在构建之前,您需要安装以下工具:

  • emcc
  • rust
  • cmake

rust 需要安装 target wasm32-unknown-emscripten

rustup target add wasm32-unknown-emscripten

开始构建

npm i
npm run build

如果一切顺利,构建完成后您将会在 dist 目录下找到编译好的文件

Keywords

FAQs

Package last updated on 07 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc