npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

image-wasm-for-war3

v2.0.1

Published

image process by wasm

Downloads

1

Readme

简介

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 目录下找到编译好的文件