Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
The is-png npm package is a utility that allows you to check if a given buffer or file is a PNG image. It is useful for validating image formats in various applications.
Check if a buffer is a PNG
This feature allows you to check if a given buffer contains a PNG image. You can read a file into a buffer and then use the isPng function to validate its format.
const isPng = require('is-png');
const fs = require('fs');
const buffer = fs.readFileSync('path/to/image.png');
console.log(isPng(buffer)); // true if the buffer is a PNG, false otherwise
Check if a file is a PNG
This feature allows you to check if a given file is a PNG image by reading the file asynchronously and then using the isPng function to validate its format.
const isPng = require('is-png');
const fs = require('fs');
fs.readFile('path/to/image.png', (err, data) => {
if (err) throw err;
console.log(isPng(data)); // true if the file is a PNG, false otherwise
});
The image-type package detects the file type of a buffer, supporting various image formats including PNG, JPEG, GIF, and more. It provides broader functionality compared to is-png, which is specific to PNG images.
The file-type package is a comprehensive utility for detecting the file type of a buffer or stream. It supports a wide range of file formats, including images, videos, documents, and more. It offers more extensive functionality compared to is-png, which is focused solely on PNG images.
The is-jpg package is similar to is-png but is specific to JPEG images. It allows you to check if a given buffer or file is a JPEG image, providing similar functionality but for a different image format.
Check if a Buffer/Uint8Array is a PNG image
Used by image-type.
$ npm install --save is-png
var readChunk = require('read-chunk'); // npm install read-chunk
var isPng = require('is-png');
var buffer = readChunk.sync('unicorn.png', 0, 4);
isPng(buffer);
//=> true
var xhr = new XMLHttpRequest();
xhr.open('GET', 'unicorn.png');
xhr.responseType = 'arraybuffer';
xhr.onload = function () {
isPng(new Uint8Array(this.response));
//=> true
};
xhr.send();
Accepts a Buffer (Node.js) or Uint8Array.
It only needs the first 4 bytes.
MIT © Sindre Sorhus
FAQs
Check if a Buffer/Uint8Array is a PNG image
We found that is-png demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.