Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
This is an experimental Node.js module to help you discover which parts of an image draw the focus of human attention.
You could use this information to modify an image or its surroundings for maximum effect.
The dominant palette of an image contains the colours that, if you had to reduce the palette to a fixed number of colours, would still represent the image most clearly to human eyes.
This should not be confused with the simpler "average" colour, often a washed-out brown or grey with a low chroma value.
A typical use case for this feature is to find the most appropriate colours for text and design elements that will appear near a given image, enhancing its appearance.
Human eyes are drawn to edges and areas with a high relative contrast.
This module creates and combines two saliency masks to calculate which region of an image contains edges and stands out more with respect to brightness and colour.
The MSRA Salient Object Database was used to discover the best thresholds for each mask.
A typical use case for this feature is to automatically remove less relevant parts of an image when cropping to fit fixed dimensions.
This is the most dominant or "heaviest" point within the Salient Region.
It is calculated by finding the midpoint of the total pixel count in each of the horizontal and vertical directions of the saliency mask.
A typical use case for this feature is to automatically centre the most relevant part of an image when cropping/hiding the top and bottom or left and right.
npm install attention
attention('input.jpg')
.swatches(1)
.palette(function(err, palette) {
palette.swatches.forEach(function(swatch) {
console.dir(swatch);
});
});
outputs:
{r: 96, g: 73, b: 58, css: '#60493a', ...}
attention('input.jpg')
.region(function(err, region) {
console.dir(region);
});
outputs:
{ top: 29, left: 17, bottom: 555, right: 485, ... }
attention('input.jpg')
.point(function(err, point) {
console.dir(region);
});
outputs:
{ x: 293, y: 117, ... }
Constructor to which further methods are chained. input
, if present, can be one of:
Calculates the dominant palette for the input image, with the number of colours limited to the value passed to swatches()
.
callback
gets the arguments (err, palette)
where palette
has the attributes:
swatches
: an array of sRGB colours split into integral (0-255) red, green, and blue components as well as a handy css
String in hex notation.duration
: the length of time taken to find the palette, in milliseconds.Set count
to the number of distinct colour swatches required, defaulting to a value of 10.
Calculates the most salient region of the input image.
callback
gets the arguments (err, region)
where region
contains the edges of the salient region in pixels from the top-left corner of the input:
top
left
bottom
right
The region
Object also contains:
width
: the width of the input image.height
: the height of the input image.duration
: the length of time taken to find the salient region, in milliseconds.Calculates the focal point of the input image.
callback
gets the arguments (err, point)
where point
contains the coordinates of the focal point from the top-left corner of the input:
x
y
The point
Object also contains:
width
: the width of the input image.height
: the height of the input image.duration
: the length of time taken to find the focal point, in milliseconds.This module uses John Cupitt's libvips and its marvellous new (2015) C++ API.
It also includes the source of Dennis Ranke's ExoQuant colour quantisation library as a submodule, used under the terms of the MIT Licence.
Copyright 2015 Lovell Fuller
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
FAQs
Detect the dominant palette, salient region and focal point of an image
The npm package attention receives a total of 0 weekly downloads. As such, attention popularity was classified as not popular.
We found that attention 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
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.