Gathering detailed insights and metrics for pngjs-image
Gathering detailed insights and metrics for pngjs-image
JavaScript-based PNG image encoder, decoder, and manipulator
npm install pngjs-image
Typescript
Module System
Node Version
NPM Version
94.8
Supply Chain
93.2
Quality
76
Maintenance
25
Vulnerability
97.9
License
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
22,270,311
Last Day
8,214
Last Week
53,376
Last Month
225,306
Last Year
3,195,580
MIT License
93 Stars
166 Commits
31 Forks
11 Watchers
2 Branches
5 Contributors
Updated on Jun 16, 2024
Minified
Minified + Gzipped
Latest Version
0.11.7
Package Id
pngjs-image@0.11.7
Size
39.30 kB
NPM Version
3.10.3
Node Version
6.7.0
Published on
Oct 24, 2016
Cumulative downloads
Total Downloads
Last Day
-9.3%
8,214
Compared to previous day
Last Week
1.6%
53,376
Compared to previous week
Last Month
12.7%
225,306
Compared to previous month
Last Year
-28.1%
3,195,580
Compared to previous year
JavaScript-based PNG image encoder, decoder, and manipulator
Table of Contents
##Installation
Install this module with the following command:
1npm install pngjs-image
Add the module to your package.json
dependencies:
1npm install --save pngjs-image
Add the module to your package.json
dev-dependencies:
1npm install --save-dev pngjs-image
Require the module in your source-code:
1var PNGImage = require('pngjs-image');
##Usage
Example: Creating a new image
1var image = PNGImage.createImage(100, 300); 2 3// Get width and height 4console.log(image.getWidth()); 5console.log(image.getHeight()); 6 7// Set a pixel at (20, 30) with red, having an alpha value of 100 (half-transparent) 8image.setAt(20, 30, { red:255, green:0, blue:0, alpha:100 }); 9 10// Get index of coordinate in the image buffer 11var index = image.getIndex(20, 30); 12 13// Print the red color value 14console.log(image.getRed(index)); 15 16// Get low level image object with buffer from the 'pngjs' package 17var pngjs = image.getImage(); 18 19image.writeImage('path/to/file', function (err) { 20 if (err) throw err; 21 console.log('Written to the file'); 22});
Example: Loading an image
1PNGImage.readImage('path/to/file', function (err, image) { 2 if (err) throw err; 3 4 // Get width and height 5 console.log(image.getWidth()); 6 console.log(image.getHeight()); 7 8 // Set a pixel at (20, 30) with red, having an alpha value of 100 (half-transparent) 9 image.setAt(20, 30, { red:255, green:0, blue:0, alpha:100 }); 10});
Example: Loading an image from an url
1PNGImage.readImage('https://s.yimg.com/rz/l/yahoo_en-US_f_p_142x37_2x.png', function (err, image) { 2 if (err) throw err; 3 4 // The image is in the 'image' variable if everything went well 5});
###Static-Methods
<PNGImage> = PNGImage.addFilter(key, fn)
Adds the fn
filter with identifier key
to the filter-list<PNGImage> = PNGImage.createImage(width, height)
Creates an image with the given size<PNGImage> = PNGImage.copyImage(image)
Copies an image into a new containerPNGImage.readImage(path, fn)
Loads an image from the file or url, calling the fn
function when donePNGImage.loadImage(blob, fn)
Loads an image from memory, calling the fn
function when done###Instance-Methods
<pngjs> = image.getImage()
Gets the pngjs
instance<Buffer> = image.getBlob()
Gets the data as a buffer object<int> = image.getWidth()
Gets the width of the image<int> = image.getHeight()
Gets the height of the imageimage.clip(x, y, width, height)
Clips the current image; the dimensions have to be smaller than the original imageimage.fillRect(x, y, width, height, color)
Fills the rectangle with the supplied colorimage.applyFilters(filters, returnResult)
Applies a list of filters to the image<int> = image.getIndex(x, y)
Converts the x and y coordinates to the sequential index of the image bufferimage.writeImage(path, fn)
Writes the image to the filesystem and calling the fn
function when doneimage.toBlob(fn)
Exports data to a buffer and calling the fn
function when done####Pixel manipulation
<uint32> = image.getAtIndex(idx)
Gets complete 32-bit pixel at index idx
<uint32> = image.getAt(x, y)
Gets complete 32-bit pixel at the x and y coordinate<uint32> = image.getPixel(x, y)
Gets complete 32-bit pixel at the x and y coordinateimage.setAtIndex(idx, color)
Sets a specific color at the index. A color left-off will not be modified.image.setAt(x, y, color)
Sets a specific color at the x and y coordinate. A color left-off will not be modified.image.setPixel(x, y, color)
Sets a specific color at the x and y coordinate. A color left-off will not be modified.<uint32> = image.getColorAtIndex(idx)
Gets the color components of the pixel at index idx
<uint32> = image.getColor(x, y)
Gets the color components of the pixel at the x and y coordinate<uint8> = image.getRed(idx)
Gets the red intensity at an indeximage.setRed(idx, value, opacity)
Sets the red intensity at an index<uint8> = image.getGreen(idx)
Gets the green intensity at an indeximage.setGreen(idx, value, opacity)
Sets the green intensity at an index<uint8> = image.getBlue(idx)
Gets the blue intensity at an indeximage.setBlue(idx, value, opacity)
Sets the blue intensity at an index<uint8> = image.getAlpha(idx)
Gets the alpha intensity at an indeximage.setAlpha(idx, value, opacity)
Sets the alpha intensity at an index####Pixel conversion
<uint32> = image.getBlurPixelAt(idx, funcName)
Gets the blurred color of a pixel at index idx
<uint32> = image.getYIQAtIndex(idx)
Gets the YIQ-value of a pixel at index idx
<uint32> = image.getYIQ(x, y)
Gets the YIQ-value of a pixel at the x and y coordinate<uint32> = image.getLumaAtIndex(idx)
Gets the luma of a pixel at index idx
<uint32> = image.getLuma(x, y)
Gets the luma of a pixel at the x and y coordinate<uint32> = image.getSepiaAtIndex(idx)
Gets the sepia-color of a pixel at index idx
<uint32> = image.getSepia(x, y)
Gets the sepia-color of a pixel at the x and y coordinate<uint32> = image.getLuminosityAtIndex(idx)
Gets the luminosity of a pixel at index idx
<uint32> = image.getLuminosity(x, y)
Gets the luminosity of a pixel at the x and y coordinate<uint32> = image.getLightnessAtIndex(idx)
Gets the lightness of a pixel at index idx
<uint32> = image.getLightness(x, y)
Gets the lightness of a pixel at the x and y coordinate<uint32> = image.getGrayScaleAtIndex(idx)
Gets the grayscale-value of a pixel at index idx
<uint32> = image.getGrayScale(x, y)
Gets the grayscale-value of a pixel at the x and y coordinate###Filters Following filters can be applied to an image:
##API-Documentation
Generate the documentation with following command:
1npm run docs
The documentation will be generated in the docs
folder of the module root.
##Tests
Run the tests with the following command:
1npm run test
The code-coverage will be written to the coverage
folder in the module root.
##Third-party libraries
The following third-party libraries are used by this module:
###Dependencies
###Dev-Dependencies
##License
The MIT License
Copyright 2014-2015 Yahoo Inc.
No vulnerabilities found.
Reason
license file detected
Details
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
project is archived
Details
Reason
Found 1/29 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-02-03
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More