mirror of
https://github.com/lovell/sharp.git
synced 2026-02-05 06:06:18 +01:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d0feb4156c | ||
|
|
0d1278dade | ||
|
|
1b401b1195 | ||
|
|
11daa3b4d1 | ||
|
|
88a3919ce0 | ||
|
|
c41b87303d | ||
|
|
833aaead56 | ||
|
|
ff98d2e44a | ||
|
|
fcf05f608a | ||
|
|
9baf38db44 | ||
|
|
69050ef1c8 | ||
|
|
b35b9f7850 | ||
|
|
500ae97cac | ||
|
|
d5b7040557 |
13
.cirrus.yml
Normal file
13
.cirrus.yml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
freebsd_instance:
|
||||||
|
image_family: freebsd-12-0
|
||||||
|
|
||||||
|
task:
|
||||||
|
prerequisites_script:
|
||||||
|
- sed -i '' 's/quarterly/latest/g' /etc/pkg/FreeBSD.conf
|
||||||
|
- pkg update -f
|
||||||
|
- pkg upgrade -y
|
||||||
|
- pkg install -y pkgconf vips libnghttp2 node npm
|
||||||
|
install_script:
|
||||||
|
- npm install --unsafe-perm
|
||||||
|
test_script:
|
||||||
|
- npm test
|
||||||
@@ -87,3 +87,5 @@ matrix:
|
|||||||
osx_image: xcode10
|
osx_image: xcode10
|
||||||
language: node_js
|
language: node_js
|
||||||
node_js: "13"
|
node_js: "13"
|
||||||
|
cache:
|
||||||
|
npm: false
|
||||||
|
|||||||
26
binding.gyp
26
binding.gyp
@@ -183,16 +183,22 @@
|
|||||||
},
|
},
|
||||||
'configurations': {
|
'configurations': {
|
||||||
'Release': {
|
'Release': {
|
||||||
'cflags_cc': [
|
'conditions': [
|
||||||
'-Wno-cast-function-type'
|
['OS == "linux"', {
|
||||||
],
|
'cflags_cc': [
|
||||||
'msvs_settings': {
|
'-Wno-cast-function-type'
|
||||||
'VCCLCompilerTool': {
|
]
|
||||||
'ExceptionHandling': 1
|
}],
|
||||||
}
|
['OS == "win"', {
|
||||||
},
|
'msvs_settings': {
|
||||||
'msvs_disabled_warnings': [
|
'VCCLCompilerTool': {
|
||||||
4275
|
'ExceptionHandling': 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'msvs_disabled_warnings': [
|
||||||
|
4275
|
||||||
|
]
|
||||||
|
}]
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -303,7 +303,7 @@ const data = await sharp(input)
|
|||||||
|
|
||||||
- Throws **[Error][4]** unsupported format or options
|
- Throws **[Error][4]** unsupported format or options
|
||||||
|
|
||||||
Returns **Sharp**
|
Returns **Sharp**
|
||||||
|
|
||||||
## tile
|
## tile
|
||||||
|
|
||||||
@@ -315,11 +315,11 @@ Warning: multiple sharp instances concurrently producing tile output can expose
|
|||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|
||||||
- `options` **[Object][6]?**
|
- `options` **[Object][6]?**
|
||||||
- `options.size` **[Number][9]** tile size in pixels, a value between 1 and 8192. (optional, default `256`)
|
- `options.size` **[Number][9]** tile size in pixels, a value between 1 and 8192. (optional, default `256`)
|
||||||
- `options.overlap` **[Number][9]** tile overlap in pixels, a value between 0 and 8192. (optional, default `0`)
|
- `options.overlap` **[Number][9]** tile overlap in pixels, a value between 0 and 8192. (optional, default `0`)
|
||||||
- `options.angle` **[Number][9]** tile angle of rotation, must be a multiple of 90. (optional, default `0`)
|
- `options.angle` **[Number][9]** tile angle of rotation, must be a multiple of 90. (optional, default `0`)
|
||||||
- `options.background` **([String][2] \| [Object][6])** background colour, parsed by the [color][10] module, defaults to white without transparency. (optional, default `{r:255,g:255,b:255,alpha:1}`)
|
- `options.background` **([String][2] \| [Object][6])** background colour, parsed by the [color][10] module, defaults to white without transparency. (optional, default `{r:255,g:255,b:255,alpha:1}`)
|
||||||
- `options.depth` **[String][2]?** how deep to make the pyramid, possible values are `onepixel`, `onetile` or `one`, default based on layout.
|
- `options.depth` **[String][2]?** how deep to make the pyramid, possible values are `onepixel`, `onetile` or `one`, default based on layout.
|
||||||
- `options.skipBlanks` **[Number][9]** threshold to skip tile generation, a value 0 - 255 for 8-bit images or 0 - 65535 for 16-bit images (optional, default `-1`)
|
- `options.skipBlanks` **[Number][9]** threshold to skip tile generation, a value 0 - 255 for 8-bit images or 0 - 65535 for 16-bit images (optional, default `-1`)
|
||||||
- `options.container` **[String][2]** tile container, with value `fs` (filesystem) or `zip` (compressed file). (optional, default `'fs'`)
|
- `options.container` **[String][2]** tile container, with value `fs` (filesystem) or `zip` (compressed file). (optional, default `'fs'`)
|
||||||
|
|||||||
@@ -196,6 +196,8 @@ Returns **Sharp**
|
|||||||
## trim
|
## trim
|
||||||
|
|
||||||
Trim "boring" pixels from all edges that contain values similar to the top-left pixel.
|
Trim "boring" pixels from all edges that contain values similar to the top-left pixel.
|
||||||
|
Images consisting entirely of a single colour will calculate "boring" using the alpha channel, if any.
|
||||||
|
|
||||||
The `info` response Object will contain `trimOffsetLeft` and `trimOffsetTop` properties.
|
The `info` response Object will contain `trimOffsetLeft` and `trimOffsetTop` properties.
|
||||||
|
|
||||||
### Parameters
|
### Parameters
|
||||||
|
|||||||
@@ -4,6 +4,22 @@
|
|||||||
|
|
||||||
Requires libvips v8.8.1.
|
Requires libvips v8.8.1.
|
||||||
|
|
||||||
|
#### v0.23.3 - 17<sup>th</sup> November 2019
|
||||||
|
|
||||||
|
* Ensure `trim` operation supports images contained in the alpha channel.
|
||||||
|
[#1597](https://github.com/lovell/sharp/issues/1597)
|
||||||
|
|
||||||
|
* Ensure tile `overlap` option works as expected.
|
||||||
|
[#1921](https://github.com/lovell/sharp/pull/1921)
|
||||||
|
[@rustyguts](https://github.com/rustyguts)
|
||||||
|
|
||||||
|
* Allow compilation on FreeBSD and variants (broken since v0.23.0)
|
||||||
|
[#1952](https://github.com/lovell/sharp/pull/1952)
|
||||||
|
[@pouya-eghbali](https://github.com/pouya-eghbali)
|
||||||
|
|
||||||
|
* Ensure `modulate` and other colour-based operations can co-exist.
|
||||||
|
[#1958](https://github.com/lovell/sharp/issues/1958)
|
||||||
|
|
||||||
#### v0.23.2 - 28<sup>th</sup> October 2019
|
#### v0.23.2 - 28<sup>th</sup> October 2019
|
||||||
|
|
||||||
* Add `background` option to tile output operation.
|
* Add `background` option to tile output operation.
|
||||||
|
|||||||
@@ -128,6 +128,9 @@ the help and code contributions of the following people:
|
|||||||
* [Jakub Michálek](https://github.com/Goues)
|
* [Jakub Michálek](https://github.com/Goues)
|
||||||
* [Ilya Ovdin](https://github.com/iovdin)
|
* [Ilya Ovdin](https://github.com/iovdin)
|
||||||
* [Andargor](https://github.com/Andargor)
|
* [Andargor](https://github.com/Andargor)
|
||||||
|
* [Nicolas Stepien](https://github.com/MayhemYDG)
|
||||||
|
* [Paul Neave](https://github.com/neave)
|
||||||
|
* [Brendan Kennedy](https://github.com/rustyguts)
|
||||||
|
|
||||||
Thank you!
|
Thank you!
|
||||||
|
|
||||||
|
|||||||
@@ -246,6 +246,9 @@ SHARP_DIST_BASE_URL="https://hostname/path/" npm install sharp
|
|||||||
|
|
||||||
to use `https://hostname/path/libvips-x.y.z-platform.tar.gz`.
|
to use `https://hostname/path/libvips-x.y.z-platform.tar.gz`.
|
||||||
|
|
||||||
|
To install the prebuilt sharp binaries from a custom URL, please see
|
||||||
|
[https://github.com/prebuild/prebuild-install#custom-binaries](https://github.com/prebuild/prebuild-install#custom-binaries)
|
||||||
|
|
||||||
### Licences
|
### Licences
|
||||||
|
|
||||||
This module is licensed under the terms of the
|
This module is licensed under the terms of the
|
||||||
|
|||||||
@@ -575,7 +575,7 @@ function tile (options) {
|
|||||||
if (options.overlap > this.options.tileSize) {
|
if (options.overlap > this.options.tileSize) {
|
||||||
throw is.invalidParameterError('overlap', `<= size (${this.options.tileSize})`, options.overlap);
|
throw is.invalidParameterError('overlap', `<= size (${this.options.tileSize})`, options.overlap);
|
||||||
}
|
}
|
||||||
this.options.tileOverlap = tile.overlap;
|
this.options.tileOverlap = options.overlap;
|
||||||
} else {
|
} else {
|
||||||
throw is.invalidParameterError('overlap', 'integer between 0 and 8192', options.overlap);
|
throw is.invalidParameterError('overlap', 'integer between 0 and 8192', options.overlap);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -367,7 +367,10 @@ function extract (options) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Trim "boring" pixels from all edges that contain values similar to the top-left pixel.
|
* Trim "boring" pixels from all edges that contain values similar to the top-left pixel.
|
||||||
|
* Images consisting entirely of a single colour will calculate "boring" using the alpha channel, if any.
|
||||||
|
*
|
||||||
* The `info` response Object will contain `trimOffsetLeft` and `trimOffsetTop` properties.
|
* The `info` response Object will contain `trimOffsetLeft` and `trimOffsetTop` properties.
|
||||||
|
*
|
||||||
* @param {Number} [threshold=10] the allowed difference from the top-left pixel, a number greater than zero.
|
* @param {Number} [threshold=10] the allowed difference from the top-left pixel, a number greater than zero.
|
||||||
* @returns {Sharp}
|
* @returns {Sharp}
|
||||||
* @throws {Error} Invalid parameters
|
* @throws {Error} Invalid parameters
|
||||||
|
|||||||
23
package.json
23
package.json
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "sharp",
|
"name": "sharp",
|
||||||
"description": "High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP and TIFF images",
|
"description": "High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP and TIFF images",
|
||||||
"version": "0.23.2",
|
"version": "0.23.3",
|
||||||
"author": "Lovell Fuller <npm@lovell.info>",
|
"author": "Lovell Fuller <npm@lovell.info>",
|
||||||
"homepage": "https://github.com/lovell/sharp",
|
"homepage": "https://github.com/lovell/sharp",
|
||||||
"contributors": [
|
"contributors": [
|
||||||
@@ -63,12 +63,13 @@
|
|||||||
"Jordan Prudhomme <jordan@raboland.fr>",
|
"Jordan Prudhomme <jordan@raboland.fr>",
|
||||||
"Ilya Ovdin <iovdin@gmail.com>",
|
"Ilya Ovdin <iovdin@gmail.com>",
|
||||||
"Andargor <andargor@yahoo.com>",
|
"Andargor <andargor@yahoo.com>",
|
||||||
"Paul Neave <paul.neave@gmail.com>"
|
"Paul Neave <paul.neave@gmail.com>",
|
||||||
|
"Brendan Kennedy <brenwken@gmail.com>"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"install": "(node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)",
|
"install": "(node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)",
|
||||||
"clean": "rm -rf node_modules/ build/ vendor/ .nyc_output/ coverage/ test/fixtures/output.*",
|
"clean": "rm -rf node_modules/ build/ vendor/ .nyc_output/ coverage/ test/fixtures/output.*",
|
||||||
"test": "semistandard && cc && npm run test-unit && npm run test-licensing && prebuild-ci",
|
"test": "semistandard && cpplint && npm run test-unit && npm run test-licensing && prebuild-ci",
|
||||||
"test-unit": "nyc --reporter=lcov --branches=99 mocha --slow=5000 --timeout=60000 ./test/unit/*.js",
|
"test-unit": "nyc --reporter=lcov --branches=99 mocha --slow=5000 --timeout=60000 ./test/unit/*.js",
|
||||||
"test-licensing": "license-checker --production --summary --onlyAllow=\"Apache-2.0;BSD;ISC;MIT\"",
|
"test-licensing": "license-checker --production --summary --onlyAllow=\"Apache-2.0;BSD;ISC;MIT\"",
|
||||||
"test-coverage": "./test/coverage/report.sh",
|
"test-coverage": "./test/coverage/report.sh",
|
||||||
@@ -109,7 +110,7 @@
|
|||||||
"detect-libc": "^1.0.3",
|
"detect-libc": "^1.0.3",
|
||||||
"nan": "^2.14.0",
|
"nan": "^2.14.0",
|
||||||
"npmlog": "^4.1.2",
|
"npmlog": "^4.1.2",
|
||||||
"prebuild-install": "^5.3.2",
|
"prebuild-install": "^5.3.3",
|
||||||
"semver": "^6.3.0",
|
"semver": "^6.3.0",
|
||||||
"simple-get": "^3.1.0",
|
"simple-get": "^3.1.0",
|
||||||
"tar": "^5.0.5",
|
"tar": "^5.0.5",
|
||||||
@@ -117,14 +118,14 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"async": "^3.1.0",
|
"async": "^3.1.0",
|
||||||
"cc": "^1.0.2",
|
"cc": "^2.0.1",
|
||||||
"decompress-zip": "^0.3.2",
|
"decompress-zip": "^0.3.2",
|
||||||
"documentation": "^12.1.2",
|
"documentation": "^12.1.4",
|
||||||
"exif-reader": "^1.0.3",
|
"exif-reader": "^1.0.3",
|
||||||
"icc": "^1.0.0",
|
"icc": "^1.0.0",
|
||||||
"license-checker": "^25.0.1",
|
"license-checker": "^25.0.1",
|
||||||
"mocha": "^6.2.2",
|
"mocha": "^6.2.2",
|
||||||
"mock-fs": "^4.10.2",
|
"mock-fs": "^4.10.3",
|
||||||
"nyc": "^14.1.1",
|
"nyc": "^14.1.1",
|
||||||
"prebuild": "^9.1.1",
|
"prebuild": "^9.1.1",
|
||||||
"prebuild-ci": "^3.1.0",
|
"prebuild-ci": "^3.1.0",
|
||||||
@@ -138,6 +139,9 @@
|
|||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=8.5.0"
|
"node": ">=8.5.0"
|
||||||
},
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://opencollective.com/libvips"
|
||||||
|
},
|
||||||
"semistandard": {
|
"semistandard": {
|
||||||
"env": [
|
"env": [
|
||||||
"mocha"
|
"mocha"
|
||||||
@@ -146,10 +150,7 @@
|
|||||||
"cc": {
|
"cc": {
|
||||||
"linelength": "120",
|
"linelength": "120",
|
||||||
"filter": [
|
"filter": [
|
||||||
"build/c++11",
|
"build/include"
|
||||||
"build/include",
|
|
||||||
"runtime/indentation_namespace",
|
|
||||||
"runtime/references"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <mutex>
|
#include <mutex> // NOLINT(build/c++11)
|
||||||
|
|
||||||
#include <node.h>
|
#include <node.h>
|
||||||
#include <node_buffer.h>
|
#include <node_buffer.h>
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ using vips::VImage;
|
|||||||
|
|
||||||
namespace sharp {
|
namespace sharp {
|
||||||
|
|
||||||
struct InputDescriptor {
|
struct InputDescriptor { // NOLINT(runtime/indentation_namespace)
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string file;
|
std::string file;
|
||||||
char *buffer;
|
char *buffer;
|
||||||
@@ -92,7 +92,7 @@ namespace sharp {
|
|||||||
|
|
||||||
// Create an InputDescriptor instance from a v8::Object describing an input image
|
// Create an InputDescriptor instance from a v8::Object describing an input image
|
||||||
InputDescriptor* CreateInputDescriptor(
|
InputDescriptor* CreateInputDescriptor(
|
||||||
v8::Local<v8::Object> input, std::vector<v8::Local<v8::Object>> &buffersToPersist);
|
v8::Local<v8::Object> input, std::vector<v8::Local<v8::Object>> &buffersToPersist); // NOLINT(runtime/references)
|
||||||
|
|
||||||
enum class ImageType {
|
enum class ImageType {
|
||||||
JPEG,
|
JPEG,
|
||||||
|
|||||||
@@ -191,12 +191,20 @@ namespace sharp {
|
|||||||
VImage alpha = image[image.bands() - 1];
|
VImage alpha = image[image.bands() - 1];
|
||||||
return RemoveAlpha(image)
|
return RemoveAlpha(image)
|
||||||
.colourspace(VIPS_INTERPRETATION_LCH)
|
.colourspace(VIPS_INTERPRETATION_LCH)
|
||||||
.linear({brightness, saturation, 1}, {0, 0, static_cast<double>(hue)})
|
.linear(
|
||||||
|
{ brightness, saturation, 1},
|
||||||
|
{ 0.0, 0.0, static_cast<double>(hue) }
|
||||||
|
)
|
||||||
|
.colourspace(VIPS_INTERPRETATION_sRGB)
|
||||||
.bandjoin(alpha);
|
.bandjoin(alpha);
|
||||||
} else {
|
} else {
|
||||||
return image
|
return image
|
||||||
.colourspace(VIPS_INTERPRETATION_LCH)
|
.colourspace(VIPS_INTERPRETATION_LCH)
|
||||||
.linear({brightness, saturation, 1}, {0, 0, static_cast<double>(hue)});
|
.linear(
|
||||||
|
{ brightness, saturation, 1 },
|
||||||
|
{ 0.0, 0.0, static_cast<double>(hue) }
|
||||||
|
)
|
||||||
|
.colourspace(VIPS_INTERPRETATION_sRGB);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,12 +266,22 @@ namespace sharp {
|
|||||||
if (HasAlpha(background)) {
|
if (HasAlpha(background)) {
|
||||||
background = background.flatten();
|
background = background.flatten();
|
||||||
}
|
}
|
||||||
int top, width, height;
|
int left, top, width, height;
|
||||||
int const left = image.find_trim(&top, &width, &height, VImage::option()
|
left = image.find_trim(&top, &width, &height, VImage::option()
|
||||||
->set("background", background(0, 0))
|
->set("background", background(0, 0))
|
||||||
->set("threshold", threshold));
|
->set("threshold", threshold));
|
||||||
if (width == 0 || height == 0) {
|
if (width == 0 || height == 0) {
|
||||||
throw VError("Unexpected error while trimming. Try to lower the tolerance");
|
if (HasAlpha(image)) {
|
||||||
|
// Search alpha channel
|
||||||
|
VImage alpha = image[image.bands() - 1];
|
||||||
|
VImage backgroundAlpha = alpha.extract_area(0, 0, 1, 1);
|
||||||
|
left = alpha.find_trim(&top, &width, &height, VImage::option()
|
||||||
|
->set("background", backgroundAlpha(0, 0))
|
||||||
|
->set("threshold", threshold));
|
||||||
|
}
|
||||||
|
if (width == 0 || height == 0) {
|
||||||
|
throw VError("Unexpected error while trimming. Try to lower the tolerance");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return image.extract_area(left, top, width, height);
|
return image.extract_area(left, top, width, height);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,9 @@
|
|||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
#define STAT64_STRUCT stat
|
#define STAT64_STRUCT stat
|
||||||
#define STAT64_FUNCTION stat
|
#define STAT64_FUNCTION stat
|
||||||
|
#elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
|
||||||
|
#define STAT64_STRUCT stat
|
||||||
|
#define STAT64_FUNCTION stat
|
||||||
#else
|
#else
|
||||||
#define STAT64_STRUCT stat64
|
#define STAT64_STRUCT stat64
|
||||||
#define STAT64_FUNCTION stat64
|
#define STAT64_FUNCTION stat64
|
||||||
|
|||||||
BIN
test/fixtures/expected/modulate-linear.jpg
vendored
Normal file
BIN
test/fixtures/expected/modulate-linear.jpg
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 62 KiB |
BIN
test/fixtures/image-in-alpha.png
vendored
Normal file
BIN
test/fixtures/image-in-alpha.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 70 KiB |
2
test/fixtures/index.js
vendored
2
test/fixtures/index.js
vendored
@@ -13,6 +13,7 @@ const getPath = function (filename) {
|
|||||||
// Based on the dHash gradient method - see http://www.hackerfactor.com/blog/index.php?/archives/529-Kind-of-Like-That.html
|
// Based on the dHash gradient method - see http://www.hackerfactor.com/blog/index.php?/archives/529-Kind-of-Like-That.html
|
||||||
const fingerprint = function (image, callback) {
|
const fingerprint = function (image, callback) {
|
||||||
sharp(image)
|
sharp(image)
|
||||||
|
.flatten('gray')
|
||||||
.greyscale()
|
.greyscale()
|
||||||
.normalise()
|
.normalise()
|
||||||
.resize(9, 8, { fit: sharp.fit.fill })
|
.resize(9, 8, { fit: sharp.fit.fill })
|
||||||
@@ -87,6 +88,7 @@ module.exports = {
|
|||||||
inputPngTruncated: getPath('truncated.png'), // gm convert 2569067123_aca715a2ee_o.jpg -resize 320x240 saw.png ; head -c 10000 saw.png > truncated.png
|
inputPngTruncated: getPath('truncated.png'), // gm convert 2569067123_aca715a2ee_o.jpg -resize 320x240 saw.png ; head -c 10000 saw.png > truncated.png
|
||||||
inputPngEmbed: getPath('embedgravitybird.png'), // Released to sharp under a CC BY 4.0
|
inputPngEmbed: getPath('embedgravitybird.png'), // Released to sharp under a CC BY 4.0
|
||||||
inputPngRGBWithAlpha: getPath('2569067123_aca715a2ee_o.png'), // http://www.flickr.com/photos/grizdave/2569067123/ (same as inputJpg)
|
inputPngRGBWithAlpha: getPath('2569067123_aca715a2ee_o.png'), // http://www.flickr.com/photos/grizdave/2569067123/ (same as inputJpg)
|
||||||
|
inputPngImageInAlpha: getPath('image-in-alpha.png'), // https://github.com/lovell/sharp/issues/1597
|
||||||
|
|
||||||
inputWebP: getPath('4.webp'), // http://www.gstatic.com/webp/gallery/4.webp
|
inputWebP: getPath('4.webp'), // http://www.gstatic.com/webp/gallery/4.webp
|
||||||
inputWebPWithTransparency: getPath('5_webp_a.webp'), // http://www.gstatic.com/webp/gallery3/5_webp_a.webp
|
inputWebPWithTransparency: getPath('5_webp_a.webp'), // http://www.gstatic.com/webp/gallery3/5_webp_a.webp
|
||||||
|
|||||||
@@ -122,4 +122,21 @@ describe('Modulate', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should be able to use linear and modulate together', function () {
|
||||||
|
const base = 'modulate-linear.jpg';
|
||||||
|
const actual = fixtures.path('output.' + base);
|
||||||
|
const expected = fixtures.expected(base);
|
||||||
|
|
||||||
|
const contrast = 1.5;
|
||||||
|
const brightness = 0.5;
|
||||||
|
|
||||||
|
return sharp(fixtures.testPattern)
|
||||||
|
.linear(contrast, -(128 * contrast) + 128)
|
||||||
|
.modulate({ brightness })
|
||||||
|
.toFile(actual)
|
||||||
|
.then(function () {
|
||||||
|
fixtures.assertMaxColourDistance(actual, expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
const promisify = require('util').promisify;
|
||||||
const rimraf = require('rimraf');
|
const rimraf = require('rimraf');
|
||||||
|
|
||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
@@ -150,40 +151,40 @@ describe('TIFF', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('TIFF setting xres and yres on file', function (done) {
|
it('TIFF setting xres and yres on file', () =>
|
||||||
const res = 1000.0; // inputTiff has a dpi of 300 (res*2.54)
|
|
||||||
sharp(fixtures.inputTiff)
|
sharp(fixtures.inputTiff)
|
||||||
.tiff({
|
.tiff({
|
||||||
xres: (res),
|
xres: 1000,
|
||||||
yres: (res)
|
yres: 1000
|
||||||
})
|
})
|
||||||
.toFile(fixtures.outputTiff, (err, info) => {
|
.toFile(fixtures.outputTiff)
|
||||||
if (err) throw err;
|
.then(() => sharp(fixtures.outputTiff)
|
||||||
assert.strictEqual('tiff', info.format);
|
.metadata()
|
||||||
sharp(fixtures.outputTiff).metadata(function (err, metadata) {
|
.then(({ density }) => {
|
||||||
if (err) throw err;
|
assert.strictEqual(true,
|
||||||
assert.strictEqual(metadata.density, res * 2.54); // convert to dpi
|
density === 2540 || // libvips <= 8.8.2
|
||||||
rimraf(fixtures.outputTiff, done);
|
density === 25400); // libvips >= 8.8.3
|
||||||
});
|
return promisify(rimraf)(fixtures.outputTiff);
|
||||||
});
|
})
|
||||||
});
|
)
|
||||||
|
);
|
||||||
|
|
||||||
it('TIFF setting xres and yres on buffer', function (done) {
|
it('TIFF setting xres and yres on buffer', () =>
|
||||||
const res = 1000.0; // inputTiff has a dpi of 300 (res*2.54)
|
|
||||||
sharp(fixtures.inputTiff)
|
sharp(fixtures.inputTiff)
|
||||||
.tiff({
|
.tiff({
|
||||||
xres: (res),
|
xres: 1000,
|
||||||
yres: (res)
|
yres: 1000
|
||||||
})
|
})
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer()
|
||||||
if (err) throw err;
|
.then(data => sharp(data)
|
||||||
sharp(data).metadata(function (err, metadata) {
|
.metadata()
|
||||||
if (err) throw err;
|
.then(({ density }) => {
|
||||||
assert.strictEqual(metadata.density, res * 2.54); // convert to dpi
|
assert.strictEqual(true,
|
||||||
done();
|
density === 2540 || // libvips <= 8.8.2
|
||||||
});
|
density === 25400); // libvips >= 8.8.3
|
||||||
});
|
})
|
||||||
});
|
)
|
||||||
|
);
|
||||||
|
|
||||||
it('TIFF invalid xres value should throw an error', function () {
|
it('TIFF invalid xres value should throw an error', function () {
|
||||||
assert.throws(function () {
|
assert.throws(function () {
|
||||||
|
|||||||
@@ -91,6 +91,29 @@ const assertGoogleTiles = function (directory, expectedTileSize, expectedLevels,
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Verifies tiles at specified level in a given output directory are > size+overlap
|
||||||
|
const assertTileOverlap = function (directory, tileSize, done) {
|
||||||
|
// Get sorted levels
|
||||||
|
const levels = fs.readdirSync(directory).sort((a, b) => a - b);
|
||||||
|
// Select the highest tile level
|
||||||
|
const highestLevel = levels[levels.length - 1];
|
||||||
|
// Get sorted tiles from greatest level
|
||||||
|
const tiles = fs.readdirSync(path.join(directory, highestLevel)).sort();
|
||||||
|
// Select a tile from the approximate center of the image
|
||||||
|
const squareTile = path.join(directory, highestLevel, tiles[Math.floor(tiles.length / 2)]);
|
||||||
|
|
||||||
|
sharp(squareTile).metadata(function (err, metadata) {
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
} else {
|
||||||
|
// Tile with an overlap should be larger than original size
|
||||||
|
assert.strictEqual(true, metadata.width > tileSize);
|
||||||
|
assert.strictEqual(true, metadata.height > tileSize);
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
describe('Tile', function () {
|
describe('Tile', function () {
|
||||||
it('Valid size values pass', function () {
|
it('Valid size values pass', function () {
|
||||||
[1, 8192].forEach(function (size) {
|
[1, 8192].forEach(function (size) {
|
||||||
@@ -297,7 +320,9 @@ describe('Tile', function () {
|
|||||||
assert.strictEqual(2225, info.height);
|
assert.strictEqual(2225, info.height);
|
||||||
assert.strictEqual(3, info.channels);
|
assert.strictEqual(3, info.channels);
|
||||||
assert.strictEqual('undefined', typeof info.size);
|
assert.strictEqual('undefined', typeof info.size);
|
||||||
assertDeepZoomTiles(directory, 512 + (2 * 16), 13, done);
|
assertDeepZoomTiles(directory, 512 + (2 * 16), 13, function () {
|
||||||
|
assertTileOverlap(directory, 512, done);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -41,6 +41,21 @@ describe('Trim borders', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('single colour PNG where alpha channel provides the image', () =>
|
||||||
|
sharp(fixtures.inputPngImageInAlpha)
|
||||||
|
.trim()
|
||||||
|
.toBuffer({ resolveWithObject: true })
|
||||||
|
.then(({ data, info }) => {
|
||||||
|
assert.strictEqual(true, data.length > 0);
|
||||||
|
assert.strictEqual('png', info.format);
|
||||||
|
assert.strictEqual(916, info.width);
|
||||||
|
assert.strictEqual(137, info.height);
|
||||||
|
assert.strictEqual(4, info.channels);
|
||||||
|
assert.strictEqual(-6, info.trimOffsetLeft);
|
||||||
|
assert.strictEqual(-20, info.trimOffsetTop);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
it('16-bit PNG with alpha channel', function (done) {
|
it('16-bit PNG with alpha channel', function (done) {
|
||||||
sharp(fixtures.inputPngWithTransparency16bit)
|
sharp(fixtures.inputPngWithTransparency16bit)
|
||||||
.resize(32, 32)
|
.resize(32, 32)
|
||||||
|
|||||||
Reference in New Issue
Block a user