Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
canvas-to-buffer
Advanced tools
Readme
A tiny converter to turn any graphic canvas into a buffer. With focus on speed: it doesn't create an expensive copy and makes clever use of atob()
and Uint8Array
.
Following performance tests prove that this module is using the fastest known method: Data URI to Buffer performance tests
Useful scenarios for this module:
toBuffer
part and/or you care about speedFurthermore this module is an important part of the Videomail Client whose implementation can be seen on Videomail
// I call it a Frame but you can go with i.E. CanvasConverter, whatever
var Frame = require("canvas-to-buffer");
// Drop in any canvas, i.E. from a webcam
var frame = new Frame(canvas);
// Automatically detects image type and does the conversion
var buffer = frame.toBuffer();
// Returns the chosen image type, could be `'image/png'`
var imageType = frame.getImageType();
var Frame = require("canvas-to-buffer");
var frame = new Frame(canvas, {
quality: 0.4,
image: {
types: ["webp", "png"],
},
});
The example means, it tries to encode the canvas first as webp
at the given quality before converting that data into a buffer. If that fails, i.E. the browser does not support it, then it will try again with the png
format.
Default: 0.5
Determines the quality when encoding the canvas into an image with the given type.
Default: ['webp', 'jpeg']
You know, turning a canvas into binary form requires an image type. No worries this module is able to automatically detect the supported image type in your browser.
But if you want to explicitly specify the image type for whatever reason, this is the option to use.
It can be a string or an array with max two image types.
FYI webp
images have better compression, but are supported on Google Chrome only. Hence this module automatically falls back to 'jpeg' for any other browsers. Beware that binary data for JPEGs is about 20% larger.
Just toBuffer()
and getImageType()
. Pretty self-explanatory.
But both need a callback when you use this package on the server side, see next chapter.
This package works on both sides, browser or server. For browser environments everything happens in sync, whereas on the server side it's in async and hence callbacks are needed in all public functions.
Tests can be run on your machine but you'll have to install Cairo first, see: How to install Cairo on different environments?
MIT. Copyright (C) Michael Heuberger
FAQs
Converts a Canvas graphic into a Buffer, as fast as possible and without a copy.
The npm package canvas-to-buffer receives a total of 455 weekly downloads. As such, canvas-to-buffer popularity was classified as not popular.
We found that canvas-to-buffer 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.