Coder Social home page Coder Social logo

tga's Introduction

TGA

This is a pure Node.js module for parse or write tga image file.

Requirements

  • Node.js v6

Installation

$ npm install tga --save

API

Class TGA(buffer, opt = { dontFixAlpha: false })

  • buffer: buffer is the tga file Buffer(fs.readFile)
  • opt: tga parse options
    • dontFixAlpha: some tga image is fully transparent, it will convert the alpha chanel to 255, you can turn this on if you dont want this feature.

TGA.createTgaBuffer(width, height, pixels)

  • width: image width
  • height: image height
  • pixels(Uint8Array): pixels data, [r, g, b, a, r, g, b, a]

TGA.getHeader(buffer)

  • buffer: buffer is the tga file Buffer(fs.readFile)
  • return a object contain the tga header info such as width, height and so on

Example

var fs = require('fs');
var TGA = require('tga');
var tga = new TGA(fs.readFileSync('./test.tga'));
console.log(tga.width, tga.height);
for (var i = 0; i < tga.pixels.length; i += 4) {
    // the range of r, g, b and a is [0, 255]
    console.log(tga.pixels[i], tga.pixels[i + 1], tga.pixels[i + 2], tga.pixels[i + 3]);
}

// save as another tga image
var buf = TGA.createTgaBuffer(tga.width, tga.height, tga.pixels);
fs.writeFileSync('./out.tga', buf);

// save the tga as png
var PNG = require('pngjs').PNG;
var png = new PNG({
    width: tga.width,
    height: tga.height
});
png.data = tga.pixels;
png.pack().pipe(fs.createWriteStream('./test.png'));

tga's People

Contributors

steel1990 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

alaxxel lesha-co

tga's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.