@jimp/core
Advanced tools
Comparing version 0.3.9 to 0.4.0
@@ -664,3 +664,3 @@ "use strict"; | ||
/** | ||
* Generates a perceptual hash of the image <https://en.wikipedia.org/wiki/Perceptual_hashing>. | ||
* Generates a perceptual hash of the image <https://en.wikipedia.org/wiki/Perceptual_hashing>. And pads the string. Can configure base. | ||
* @param {number} base (optional) a number between 2 and 64 representing the base for the hash (e.g. 2 is binary, 10 is decimal, 16 is hex, 64 is base 64). Defaults to 64. | ||
@@ -686,3 +686,3 @@ * @param {function(Error, Jimp)} cb (optional) a callback for when complete | ||
var hash = new _phash.default().getHash(this); | ||
var hash = this.pHash(); | ||
hash = (0, _anyBase.default)(_anyBase.default.BIN, alphabet.slice(0, base))(hash); | ||
@@ -701,2 +701,26 @@ | ||
/** | ||
* Calculates the perceptual hash | ||
* @returns {number} the perceptual hash | ||
*/ | ||
}, { | ||
key: "pHash", | ||
value: function pHash() { | ||
var pHash = new _phash.default(); | ||
return pHash.getHash(this); | ||
} | ||
/** | ||
* Calculates the hamming distance of the current image and a hash based on their perceptual hash | ||
* @param {hash} compareHash hash to compare to | ||
* @returns {number} a number ranging from 0 to 1, 0 means they are believed to be identical | ||
*/ | ||
}, { | ||
key: "distanceFromHash", | ||
value: function distanceFromHash(compareHash) { | ||
var pHash = new _phash.default(); | ||
var currentHash = pHash.getHash(this); | ||
return pHash.distance(currentHash, compareHash); | ||
} | ||
/** | ||
* Converts the image to a buffer | ||
@@ -832,2 +856,23 @@ * @param {string} mime the mime type of the image buffer to be created | ||
} | ||
}, { | ||
key: "hasAlpha", | ||
/** | ||
* Determine if the image contains opaque pixels. | ||
* @return {boolean} hasAlpha whether the image contains opaque pixels | ||
*/ | ||
value: function hasAlpha() { | ||
for (var yIndex = 0; yIndex < this.bitmap.height; yIndex++) { | ||
for (var xIndex = 0; xIndex < this.bitmap.width; xIndex++) { | ||
var idx = this.bitmap.width * yIndex + xIndex << 2; | ||
var alpha = this.bitmap.data[idx + 3]; | ||
if (alpha !== 0xff) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
}]); | ||
@@ -839,2 +884,3 @@ | ||
function addConstants(constants) { | ||
var jimpInstance = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Jimp; | ||
Object.entries(constants).forEach(function (_ref) { | ||
@@ -845,3 +891,3 @@ var _ref2 = _slicedToArray(_ref, 2), | ||
Jimp[name] = value; | ||
jimpInstance[name] = value; | ||
}); | ||
@@ -851,2 +897,3 @@ } | ||
function addJimpMethods(methods) { | ||
var jimpInstance = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Jimp; | ||
Object.entries(methods).forEach(function (_ref3) { | ||
@@ -857,3 +904,3 @@ var _ref4 = _slicedToArray(_ref3, 2), | ||
Jimp.prototype[name] = value; | ||
jimpInstance.prototype[name] = value; | ||
}); | ||
@@ -1046,2 +1093,14 @@ } | ||
/** | ||
* Calculates the hamming distance of two images based on their perceptual hash | ||
* @param {hash} hash1 a pHash | ||
* @param {hash} hash2 a pHash | ||
* @returns {number} a number ranging from 0 to 1, 0 means they are believed to be identical | ||
*/ | ||
Jimp.compareHashes = function (hash1, hash2) { | ||
var phash = new _phash.default(); | ||
return phash.distance(hash1, hash2); | ||
}; | ||
/** | ||
* Compute color difference | ||
@@ -1048,0 +1107,0 @@ * 0 means no difference, 1 means maximum difference. |
@@ -122,3 +122,3 @@ "use strict"; | ||
} catch (error) { | ||
cb.call(this, error, this); | ||
return cb.call(this, error, this); | ||
} | ||
@@ -125,0 +125,0 @@ |
@@ -580,3 +580,3 @@ function isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } | ||
/** | ||
* Generates a perceptual hash of the image <https://en.wikipedia.org/wiki/Perceptual_hashing>. | ||
* Generates a perceptual hash of the image <https://en.wikipedia.org/wiki/Perceptual_hashing>. And pads the string. Can configure base. | ||
* @param {number} base (optional) a number between 2 and 64 representing the base for the hash (e.g. 2 is binary, 10 is decimal, 16 is hex, 64 is base 64). Defaults to 64. | ||
@@ -602,3 +602,3 @@ * @param {function(Error, Jimp)} cb (optional) a callback for when complete | ||
var hash = new ImagePHash().getHash(this); | ||
var hash = this.pHash(); | ||
hash = anyBase(anyBase.BIN, alphabet.slice(0, base))(hash); | ||
@@ -617,2 +617,26 @@ | ||
/** | ||
* Calculates the perceptual hash | ||
* @returns {number} the perceptual hash | ||
*/ | ||
}, { | ||
key: "pHash", | ||
value: function pHash() { | ||
var pHash = new ImagePHash(); | ||
return pHash.getHash(this); | ||
} | ||
/** | ||
* Calculates the hamming distance of the current image and a hash based on their perceptual hash | ||
* @param {hash} compareHash hash to compare to | ||
* @returns {number} a number ranging from 0 to 1, 0 means they are believed to be identical | ||
*/ | ||
}, { | ||
key: "distanceFromHash", | ||
value: function distanceFromHash(compareHash) { | ||
var pHash = new ImagePHash(); | ||
var currentHash = pHash.getHash(this); | ||
return pHash.distance(currentHash, compareHash); | ||
} | ||
/** | ||
* Converts the image to a buffer | ||
@@ -748,2 +772,23 @@ * @param {string} mime the mime type of the image buffer to be created | ||
} | ||
}, { | ||
key: "hasAlpha", | ||
/** | ||
* Determine if the image contains opaque pixels. | ||
* @return {boolean} hasAlpha whether the image contains opaque pixels | ||
*/ | ||
value: function hasAlpha() { | ||
for (var yIndex = 0; yIndex < this.bitmap.height; yIndex++) { | ||
for (var xIndex = 0; xIndex < this.bitmap.width; xIndex++) { | ||
var idx = this.bitmap.width * yIndex + xIndex << 2; | ||
var alpha = this.bitmap.data[idx + 3]; | ||
if (alpha !== 0xff) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
}]); | ||
@@ -755,2 +800,3 @@ | ||
export function addConstants(constants) { | ||
var jimpInstance = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Jimp; | ||
Object.entries(constants).forEach(function (_ref) { | ||
@@ -761,6 +807,7 @@ var _ref2 = _slicedToArray(_ref, 2), | ||
Jimp[name] = value; | ||
jimpInstance[name] = value; | ||
}); | ||
} | ||
export function addJimpMethods(methods) { | ||
var jimpInstance = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Jimp; | ||
Object.entries(methods).forEach(function (_ref3) { | ||
@@ -771,3 +818,3 @@ var _ref4 = _slicedToArray(_ref3, 2), | ||
Jimp.prototype[name] = value; | ||
jimpInstance.prototype[name] = value; | ||
}); | ||
@@ -959,2 +1006,14 @@ } | ||
/** | ||
* Calculates the hamming distance of two images based on their perceptual hash | ||
* @param {hash} hash1 a pHash | ||
* @param {hash} hash2 a pHash | ||
* @returns {number} a number ranging from 0 to 1, 0 means they are believed to be identical | ||
*/ | ||
Jimp.compareHashes = function (hash1, hash2) { | ||
var phash = new ImagePHash(); | ||
return phash.distance(hash1, hash2); | ||
}; | ||
/** | ||
* Compute color difference | ||
@@ -961,0 +1020,0 @@ * 0 means no difference, 1 means maximum difference. |
@@ -102,3 +102,3 @@ import fileType from 'file-type'; | ||
} catch (error) { | ||
cb.call(this, error, this); | ||
return cb.call(this, error, this); | ||
} | ||
@@ -105,0 +105,0 @@ |
{ | ||
"name": "@jimp/core", | ||
"version": "0.3.9", | ||
"version": "0.4.0", | ||
"description": "Jimp core", | ||
@@ -21,6 +21,5 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"test:node": "cross-env BABEL_ENV=test mocha --require @babel/register test/**/*.js", | ||
"test:node:watch": "npm run test:node -- --reporter min --watch", | ||
"test:node:coverage": "nyc npm run test:node", | ||
"test": "npm run test:node:coverage", | ||
"test": "cross-env BABEL_ENV=test mocha --require @babel/register test/**/*.js", | ||
"test:watch": "npm run test -- --reporter min --watch", | ||
"test:coverage": "nyc npm run test", | ||
"build": "npm run build:node:production && npm run build:module", | ||
@@ -37,3 +36,3 @@ "build:watch": "npm run build:node:debug -- -- --watch --verbose", | ||
"dependencies": { | ||
"@jimp/utils": "^0.3.9", | ||
"@jimp/utils": "^0.4.0", | ||
"any-base": "^1.1.0", | ||
@@ -57,3 +56,3 @@ "buffer": "^5.2.0", | ||
}, | ||
"gitHead": "cc0669daf5b35d7bb0cb9d2a07a3ab4215bbed79" | ||
"gitHead": "4daa956fce81c656ffa10d814a08412ef09b7e69" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
368343
3349
+ Added@jimp/utils@0.4.0(transitive)
- Removed@jimp/utils@0.3.9(transitive)
Updated@jimp/utils@^0.4.0