Skip to content

Commit

Permalink
Merge pull request #10 from fast-average-color/absolute_url
Browse files Browse the repository at this point in the history
Add support for absolute urls
  • Loading branch information
hcodes authored Apr 7, 2022
2 parents 8d7cc02 + daf1e5c commit d1f4c1e
Show file tree
Hide file tree
Showing 11 changed files with 2,918 additions and 1,522 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x, 16.x]
node-version: [12.x, 14.x, 16.x]
steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v2.2.0
- Added support for absolute urls
- Updated deps in package.json

# v2.1.0
Updated deps in package.json

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Denis Seleznev
Copyright (c) 2022 Denis Seleznev

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ printAverageColor();
#### Parameters
```js
/**
* @param {string | Buffer} [filename] filename, Buffer or data64 string
* @param {string | Buffer} [filename] filename, url, Buffer or data64 string
* @param {Object} [options]
* @param {number[]} [options.defaultColor=[0, 0, 0, 0]]
* @param {number[]} [options.ignoredColor] [red (0-255), green (0-255), blue (0-255), alpha (0-255)]
Expand Down
2 changes: 1 addition & 1 deletion dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/// <reference types="node" />
import { FastAverageColorOptions, FastAverageColorResult } from 'fast-average-color';
export declare function getAverageColor(filename: string | Buffer, options?: FastAverageColorOptions): Promise<FastAverageColorResult>;
export declare function getAverageColor(resource: string | Buffer, options?: FastAverageColorOptions): Promise<FastAverageColorResult>;
14 changes: 10 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAverageColor = void 0;
const sharp_1 = __importDefault(require("sharp"));
const node_fetch_1 = __importDefault(require("node-fetch"));
const fast_average_color_1 = __importDefault(require("fast-average-color"));
const fac = new fast_average_color_1.default();
const MIN_SIZE = 10;
Expand Down Expand Up @@ -52,14 +53,19 @@ function prepareSizeAndPosition(originalSize, options) {
destHeight
};
}
async function getAverageColor(filename, options = {}) {
async function getAverageColor(resource, options = {}) {
var _a, _b;
let input = filename;
if (typeof filename === 'string') {
const base64 = filename.split(/^data:image\/.*?;base64,/)[1];
let input = resource;
if (typeof resource === 'string') {
const base64 = resource.split(/^data:image\/.*?;base64,/)[1];
if (base64) {
input = Buffer.from(base64, 'base64');
}
else if (resource.search(/^https?:\/\//) !== -1) {
const response = await (0, node_fetch_1.default)(resource);
const arrayBuffer = await response.arrayBuffer();
input = Buffer.from(arrayBuffer);
}
}
const left = (_a = options.left) !== null && _a !== void 0 ? _a : 0;
const top = (_b = options.top) !== null && _b !== void 0 ? _b : 0;
Expand Down
Loading

0 comments on commit d1f4c1e

Please sign in to comment.