fast-average-color-node
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -0,2 +1,5 @@ | ||
# v1.0.2 | ||
Fixes for options: left, top, width and height #1. | ||
# v1.0.1 | ||
Fixes for typings. |
@@ -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)); | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6875
44