Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fast-average-color-node

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-average-color-node - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

3

CHANGELOG.md

@@ -0,2 +1,5 @@

# v1.0.2
Fixes for options: left, top, width and height #1.
# v1.0.1
Fixes for typings.

12

dist/index.js

@@ -11,10 +11,16 @@ "use strict";

async function getAverageColor(filename, options) {
var _a, _b, _c, _d;
const image = await canvas_1.loadImage(filename);
const { width, height } = image;
const canvas = canvas_1.createCanvas(width, height);
const naturalWidth = image.width;
const naturalHeight = image.height;
const canvas = canvas_1.createCanvas(naturalWidth, naturalHeight);
const context = canvas.getContext('2d');
context.drawImage(image, 0, 0);
const imageData = context.getImageData(0, 0, width, height);
const left = (_a = options === null || options === void 0 ? void 0 : options.left) !== null && _a !== void 0 ? _a : 0;
const top = (_b = options === null || options === void 0 ? void 0 : options.top) !== null && _b !== void 0 ? _b : 0;
const width = (_c = options === null || options === void 0 ? void 0 : options.width) !== null && _c !== void 0 ? _c : naturalWidth;
const height = (_d = options === null || options === void 0 ? void 0 : options.height) !== null && _d !== void 0 ? _d : naturalHeight;
const imageData = context.getImageData(left, top, width, height);
return fac.prepareResult(fac.getColorFromArray4(imageData.data, options));
}
exports.getAverageColor = getAverageColor;
{
"name": "fast-average-color-node",
"version": "1.0.1",
"version": "1.0.2",
"description": "A simple library that calculates the average color of images in Node.js.",

@@ -24,5 +24,5 @@ "main": "dist/index.js",

"devDependencies": {
"jest": "^26.6.0",
"ts-jest": "^26.4.1",
"typescript": "^4.0.3"
"jest": "^26.6.3",
"ts-jest": "^26.4.4",
"typescript": "^4.1.2"
},

@@ -29,0 +29,0 @@ "engines": {

@@ -8,11 +8,18 @@ import { createCanvas, loadImage } from 'canvas';

const image = await loadImage(filename);
const { width, height } = image;
const canvas = createCanvas(width, height);
const naturalWidth = image.width;
const naturalHeight = image.height;
const canvas = createCanvas(naturalWidth, naturalHeight);
const context = canvas.getContext('2d');
context.drawImage(image, 0, 0);
const imageData = context.getImageData(0, 0, width, height);
const left = options?.left ?? 0;
const top = options?.top ?? 0;
const width = options?.width ?? naturalWidth;
const height = options?.height ?? naturalHeight;
const imageData = context.getImageData(left, top, width, height);
return fac.prepareResult(fac.getColorFromArray4(imageData.data, options));
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc