Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #21 from andrew/master

Improved readme
  • Loading branch information...
commit 39767dd7b362b8d04c799797c831ec8ff90e20b2 2 parents 21031e8 + 2c4d5b8
@pkrumins authored
Showing with 44 additions and 17 deletions.
  1. +44 −17 readme.txt → readme.md
View
61 readme.txt → readme.md
@@ -1,3 +1,6 @@
+node-png
+--------
+
This is a node.js module, writen in C++, that uses libpng to produce a PNG
image (in memory) from RGB or RGBA buffers.
@@ -21,7 +24,9 @@ Png
The `Png` object takes 4 arguments in its constructor:
- var png = new Png(buffer, width, height, buffer_type);
+``` javascript
+var png = new Png(buffer, width, height, buffer_type);
+```
The first argument, `buffer`, is a node.js `Buffer` filled with RGB(A) values.
The second argument is integer width of the image.
@@ -32,14 +37,18 @@ The constructed `png` object has the `encode` method that's asynchronous in natu
You give it a callback and it will call your function with a node.js Buffer object
containing the encoded PNG data when it's done:
- png.encode(function (png_image) {
- // ...
- });
+``` javascript
+png.encode(function (png_image) {
+ // ...
+});
+```
The constructed `png` object also has `encodeSync` method that does the encoding
synchronously and returns Buffer with PNG image data:
- var png_image = png.encode();
+``` javascript
+var png_image = png.encode();
+```
You can either send the png_image to the browser, or write to a file, or
do something else with it. See `examples/` directory for some examples.
@@ -50,7 +59,9 @@ FixedPngStack
The `FixedPngStack` object takes 3 arguments in its constructor:
- var fixed_png = new FixedPngStack(width, height, buffer_type);
+``` javascript
+var fixed_png = new FixedPngStack(width, height, buffer_type);
+```
The first argument is integer width of the canvas image.
The second argument is integer height of the canvas image.
@@ -59,7 +70,9 @@ The third argument is 'rgb', 'bgr', 'rgba or 'bgra'. Defaults to 'rgb'.
Now you can use the `push` method of `fixed_png` object to push buffers
to the canvas. The `push` method takes 5 arguments:
- fixed_png.push(buffer, x, y, w, h);
+``` javascript
+fixed_png.push(buffer, x, y, w, h);
+```
It pushes an RGB(A) image in `buffer` of width `w` and height `h` to the canvas
position (x, y). You can push as many buffers to canvas as you want. After
@@ -75,7 +88,9 @@ DynamicPngStack
The `DynamicPngStack` object doesn't take any dimension arguments because its
width and height is dynamically computed. To create it, do:
- var dynamic_png = new DynamicPngStack(buffer_type);
+``` javascript
+var dynamic_png = new DynamicPngStack(buffer_type);
+```
The `buffer_type` again is 'rgb', 'bgr', 'rgba' or 'bgra', depending on what type
of buffers you're gonna push to `dynamic_png`.
@@ -100,27 +115,37 @@ together. One with width 100x40 at position (5, 10) and the other with
width 20x20 at position (2, 210). First you create the DynamicPngStack
object:
- var dynamic_png = new DynamicPngStack();
+``` javascript
+var dynamic_png = new DynamicPngStack();
+```
Next you push the RGB(A) buffers of the two PNGs to it:
- dynamic_png.push(png1_buf, 5, 10, 100, 40);
- dynamic_png.push(png2_buf, 2, 210, 20, 20);
+``` javascript
+dynamic_png.push(png1_buf, 5, 10, 100, 40);
+dynamic_png.push(png2_buf, 2, 210, 20, 20);
+```
Now you can call `encode` to produce the final PNG:
- var png = dynamic_png.encodeSync();
+``` javascript
+var png = dynamic_png.encodeSync();
+```
Now let's see what the dimensions are,
- var dims = dynamic_png.dimensions();
+``` javascript
+var dims = dynamic_png.dimensions();
+```
Same asynchronously:
- dynamic_png.encode(function (png, dims) {
- // png is the PNG image (in a node.js Buffer)
- // dims are its dimensions
- });
+``` javascript
+dynamic_png.encode(function (png, dims) {
+ // png is the PNG image (in a node.js Buffer)
+ // dims are its dimensions
+});
+```
The x position `dims.x` is 2 because the 2nd png is closer to the left.
The y position `dims.y` is 10 because the 1st png is closer to the top.
@@ -138,7 +163,9 @@ How to compile?
To get the node-png module compiled, you need to have libpng and node.js
installed. Then just run:
+``` bash
node-waf configure build
+```
to build node-png module. It will be called `png.node`. To use it, make sure
it's in NODE_PATH.
Please sign in to comment.
Something went wrong with that request. Please try again.