Security News
New Proposed CISA Mandate Would Require Critical Infrastructure to Report Ransom Payments Within 24 Hours
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
imtool
Advanced tools
Client-side canvas-based image manipulation library.
Weekly downloads
Readme
Canvas-based TypeScript image manipulation library.
Quickstart:
npm install imtool
# or:
yarn add imtool
Client-side image manipulation:
The source code of the live demo is available here: https://github.com/mat-sz/imtool-demo
import { fromImage } from 'imtool';
async function example() {
const tool = await fromImage('./image.png');
return await tool.thumbnail(250).toDataURL();
}
import { fromScreen } from 'imtool';
async function example() {
const tool = await fromScreen();
return await tool.crop(50, 50, 200, 200).toBlob();
}
import { fromWebcam } from 'imtool';
async function example() {
const tool = await fromWebcam();
return await tool.crop(50, 50, 500, 500).thumbnail(250).toDataURL();
}
imtool
provides 6 easy to use from*
functions, all of the functions return a Promise:
Creates an instance of ImTool
from an URL, Blob, File or HTMLImageElement.
In case of URL and HTMLImageElement being used the image must be accessible to the current origin, by either being from the same origin or by being from an origin specified in Access-Control-Allow-Origin
header on the response from the desired URL.
Creates an instance of ImTool
from an HTMLVideoElement.
The video must be accessible to the current origin, by either being from the same origin or by being from an origin specified in Access-Control-Allow-Origin
header on the response from the desired URL.
Creates an instance of ImTool
from an HTMLCanvasElement.
The canvas must not be tainted.
Asks the user for the permission to access their webcam, captures the image, and creates an instance of ImTool
.
Must be called directly from an user action, for example: a button press.
Asks the user for the permission to access their desktop capture, captures the image, and creates an instance of ImTool
.
Must be called directly from an user action, for example: a button press. May be not supported on some browsers, like Safari (including all internet browsers on iOS), Internet Explorer and older versions of other browsers.
Creates an instance of ImTool
from MediaStream (must contain at least one video track).
All functions return the same instance of ImTool
, allowing for easy chaining.
Creates a thumbnail. The code for this comes from my older project, nailit.
maxSize
specifies the maximum size (either width or height) of the resulting image.cover
when set to true will cause the resulting image to be a square and the input image will be centered with its smallest dimension becoming as large as maxDimension and the overflow being cut off.Scales the image down/up to specified width
and height
.
Moves the input image from (x
, y
) to (0, 0) and crops it down to the specified width
and height
.
Flips the image vertically.
Flips the image horizontally.
Rotates the input image by rad
radians relative to the center of the image. The output image size will be increased to fit the entire rotated image.
Rotates the input image by degrees
degrees relative to the center of the image. The output image size will be increased to fit the entire rotated image.
Set the background color of the current image.
Sets the output mimetype (most commmonly supported ones are image/jpeg
and image/png
).
Output quality (for lossy compression), a number between 0.0 and 1.0.
Outputs a Blob.
Outputs a blob URL.
Outputs a data URL.
Outputs a <canvas>
.
Outputs an <img>
.
Causes the resulting file to be downloaded by the browser with a given name.
Outputs a File
that can be easily sent with FormData
.
All of the following are readonly unless noted otherwise.
Width of the output image.
Height of the output image.
Width of the input image.
Height of the input image.
FAQs
Client-side canvas-based image manipulation library.
The npm package imtool receives a total of 745 weekly downloads. As such, imtool popularity was classified as not popular.
We found that imtool demonstrated a healthy version release cadence and project activity because the last version was released less than 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
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
Security News
Redis is no longer OSS, breaking its explicit commitment to remain under the BSD 3-Clause License forever. This has angered contributors who are now working to fork the software.
Product
Socket AI now enables 'AI detected potential malware' alerts by default, ensuring users benefit from AI-powered state-of-the-art malware detection without needing to opt-in.