mirror of
https://github.com/lovell/sharp.git
synced 2026-02-06 06:36:17 +01:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
09263455b5 | ||
|
|
ddc23493d4 | ||
|
|
54a71fc142 | ||
|
|
b1a9bf10a2 | ||
|
|
97cfbe1b63 | ||
|
|
0ee8c63551 | ||
|
|
0ac5a9ad82 | ||
|
|
6e51f2d608 |
@@ -279,6 +279,8 @@ Use tile-based deep zoom (image pyramid) output.
|
|||||||
Set the format and options for tile images via the `toFormat`, `jpeg`, `png` or `webp` functions.
|
Set the format and options for tile images via the `toFormat`, `jpeg`, `png` or `webp` functions.
|
||||||
Use a `.zip` or `.szi` file extension with `toFile` to write to a compressed archive file format.
|
Use a `.zip` or `.szi` file extension with `toFile` to write to a compressed archive file format.
|
||||||
|
|
||||||
|
Warning: multiple sharp instances concurrently producing tile output can expose a possible race condition in some versions of libgsf.
|
||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `tile` **[Object][15]?**
|
- `tile` **[Object][15]?**
|
||||||
|
|||||||
@@ -4,6 +4,12 @@
|
|||||||
|
|
||||||
Requires libvips v8.6.1.
|
Requires libvips v8.6.1.
|
||||||
|
|
||||||
|
#### v0.20.3 - 29<sup>th</sup> May 2018
|
||||||
|
|
||||||
|
* Fix tint operation by ensuring LAB interpretation and allowing negative values.
|
||||||
|
[#1235](https://github.com/lovell/sharp/issues/1235)
|
||||||
|
[@wezside](https://github.com/wezside)
|
||||||
|
|
||||||
#### v0.20.2 - 28<sup>th</sup> April 2018
|
#### v0.20.2 - 28<sup>th</sup> April 2018
|
||||||
|
|
||||||
* Add tint operation to set image chroma.
|
* Add tint operation to set image chroma.
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ yarn add sharp
|
|||||||
### Building from source
|
### Building from source
|
||||||
|
|
||||||
Pre-compiled binaries for sharp are provided for use with
|
Pre-compiled binaries for sharp are provided for use with
|
||||||
Node versions 4, 6, 8 and 9 on
|
Node versions 4, 6, 8 and 10 on
|
||||||
64-bit Windows, OS X and Linux platforms.
|
64-bit Windows, OS X and Linux platforms.
|
||||||
|
|
||||||
Sharp will be built from source at install time when:
|
Sharp will be built from source at install time when:
|
||||||
@@ -161,6 +161,18 @@ Set the Lambda runtime to Node.js 6.10.
|
|||||||
|
|
||||||
To get the best performance select the largest memory available. A 1536 MB function provides ~12x more CPU time than a 128 MB function.
|
To get the best performance select the largest memory available. A 1536 MB function provides ~12x more CPU time than a 128 MB function.
|
||||||
|
|
||||||
|
### NW.js
|
||||||
|
|
||||||
|
Run the `nw-gyp` tool after installation.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
cd node-modules/sharp
|
||||||
|
nw-gyp rebuild --arch=x64 --target=[your nw version]
|
||||||
|
node node_modules/sharp/install/dll-copy
|
||||||
|
```
|
||||||
|
|
||||||
|
See also http://docs.nwjs.io/en/latest/For%20Users/Advanced/Use%20Native%20Node%20Modules/
|
||||||
|
|
||||||
### Build tools
|
### Build tools
|
||||||
|
|
||||||
* [gulp-responsive](https://www.npmjs.com/package/gulp-responsive)
|
* [gulp-responsive](https://www.npmjs.com/package/gulp-responsive)
|
||||||
|
|||||||
@@ -152,8 +152,8 @@ const Sharp = function (input, options) {
|
|||||||
fastShrinkOnLoad: true,
|
fastShrinkOnLoad: true,
|
||||||
// operations
|
// operations
|
||||||
background: [0, 0, 0, 255],
|
background: [0, 0, 0, 255],
|
||||||
tintA: 0,
|
tintA: 128,
|
||||||
tintB: 0,
|
tintB: 128,
|
||||||
flatten: false,
|
flatten: false,
|
||||||
negate: false,
|
negate: false,
|
||||||
medianSize: 0,
|
medianSize: 0,
|
||||||
|
|||||||
@@ -390,6 +390,8 @@ function toFormat (format, options) {
|
|||||||
* Set the format and options for tile images via the `toFormat`, `jpeg`, `png` or `webp` functions.
|
* Set the format and options for tile images via the `toFormat`, `jpeg`, `png` or `webp` functions.
|
||||||
* Use a `.zip` or `.szi` file extension with `toFile` to write to a compressed archive file format.
|
* Use a `.zip` or `.szi` file extension with `toFile` to write to a compressed archive file format.
|
||||||
*
|
*
|
||||||
|
* Warning: multiple sharp instances concurrently producing tile output can expose a possible race condition in some versions of libgsf.
|
||||||
|
*
|
||||||
* @example
|
* @example
|
||||||
* sharp('input.tiff')
|
* sharp('input.tiff')
|
||||||
* .png()
|
* .png()
|
||||||
|
|||||||
18
package.json
18
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.20.2",
|
"version": "0.20.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": [
|
||||||
@@ -83,24 +83,24 @@
|
|||||||
"color": "^3.0.0",
|
"color": "^3.0.0",
|
||||||
"detect-libc": "^1.0.3",
|
"detect-libc": "^1.0.3",
|
||||||
"nan": "^2.10.0",
|
"nan": "^2.10.0",
|
||||||
"fs-copy-file-sync": "^1.0.1",
|
"fs-copy-file-sync": "^1.1.1",
|
||||||
"npmlog": "^4.1.2",
|
"npmlog": "^4.1.2",
|
||||||
"prebuild-install": "^2.5.3",
|
"prebuild-install": "^4.0.0",
|
||||||
"semver": "^5.5.0",
|
"semver": "^5.5.0",
|
||||||
"simple-get": "^2.8.1",
|
"simple-get": "^2.8.1",
|
||||||
"tar": "^4.4.1",
|
"tar": "^4.4.4",
|
||||||
"tunnel-agent": "^0.6.0"
|
"tunnel-agent": "^0.6.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"async": "^2.6.0",
|
"async": "^2.6.1",
|
||||||
"cc": "^1.0.2",
|
"cc": "^1.0.2",
|
||||||
"decompress-zip": "^0.3.1",
|
"decompress-zip": "^0.3.1",
|
||||||
"documentation": "^6.3.2",
|
"documentation": "^7.1.0",
|
||||||
"exif-reader": "^1.0.2",
|
"exif-reader": "^1.0.2",
|
||||||
"icc": "^1.0.0",
|
"icc": "^1.0.0",
|
||||||
"mocha": "^5.1.1",
|
"mocha": "^5.2.0",
|
||||||
"nyc": "^11.7.1",
|
"nyc": "^11.8.0",
|
||||||
"prebuild": "^7.4.0",
|
"prebuild": "^7.6.0",
|
||||||
"prebuild-ci": "^2.2.3",
|
"prebuild-ci": "^2.2.3",
|
||||||
"rimraf": "^2.6.2",
|
"rimraf": "^2.6.2",
|
||||||
"semistandard": "^12.0.1"
|
"semistandard": "^12.0.1"
|
||||||
|
|||||||
@@ -83,9 +83,9 @@ class MetadataWorker : public Nan::AsyncWorker {
|
|||||||
baton->iccLength = iccLength;
|
baton->iccLength = iccLength;
|
||||||
}
|
}
|
||||||
// IPTC
|
// IPTC
|
||||||
if (image.get_typeof(VIPS_META_IPCT_NAME) == VIPS_TYPE_BLOB) {
|
if (image.get_typeof(VIPS_META_IPTC_NAME) == VIPS_TYPE_BLOB) {
|
||||||
size_t iptcLength;
|
size_t iptcLength;
|
||||||
void const *iptc = image.get_blob(VIPS_META_IPCT_NAME, &iptcLength);
|
void const *iptc = image.get_blob(VIPS_META_IPTC_NAME, &iptcLength);
|
||||||
baton->iptc = static_cast<char *>(g_malloc(iptcLength));
|
baton->iptc = static_cast<char *>(g_malloc(iptcLength));
|
||||||
memcpy(baton->iptc, iptc, iptcLength);
|
memcpy(baton->iptc, iptc, iptcLength);
|
||||||
baton->iptcLength = iptcLength;
|
baton->iptcLength = iptcLength;
|
||||||
|
|||||||
@@ -161,13 +161,14 @@ namespace sharp {
|
|||||||
if (typeBeforeTint == VIPS_INTERPRETATION_RGB) {
|
if (typeBeforeTint == VIPS_INTERPRETATION_RGB) {
|
||||||
typeBeforeTint = VIPS_INTERPRETATION_sRGB;
|
typeBeforeTint = VIPS_INTERPRETATION_sRGB;
|
||||||
}
|
}
|
||||||
// Create 2 band image with every pixel set to the tint chroma
|
|
||||||
std::vector<double> chromaPixel {a, b};
|
|
||||||
VImage chroma = image.new_from_image(chromaPixel);
|
|
||||||
// Extract luminance
|
// Extract luminance
|
||||||
VImage luminance = image.colourspace(VIPS_INTERPRETATION_LAB)[0];
|
VImage luminance = image.colourspace(VIPS_INTERPRETATION_LAB)[0];
|
||||||
// Create the tinted version by combining the L from the original and the chroma from the tint
|
// Create the tinted version by combining the L from the original and the chroma from the tint
|
||||||
VImage tinted = luminance.bandjoin(chroma).colourspace(typeBeforeTint);
|
std::vector<double> chroma {a, b};
|
||||||
|
VImage tinted = luminance
|
||||||
|
.bandjoin(chroma)
|
||||||
|
.copy(VImage::option()->set("interpretation", VIPS_INTERPRETATION_LAB))
|
||||||
|
.colourspace(typeBeforeTint);
|
||||||
// Attach original alpha channel, if any
|
// Attach original alpha channel, if any
|
||||||
if (HasAlpha(image)) {
|
if (HasAlpha(image)) {
|
||||||
// Extract original alpha channel
|
// Extract original alpha channel
|
||||||
|
|||||||
@@ -683,7 +683,7 @@ class PipelineWorker : public Nan::AsyncWorker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Tint the image
|
// Tint the image
|
||||||
if (baton->tintA > 0 || baton->tintB > 0) {
|
if (baton->tintA < 128.0 || baton->tintB < 128.0) {
|
||||||
image = sharp::Tint(image, baton->tintA, baton->tintB);
|
image = sharp::Tint(image, baton->tintA, baton->tintB);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -157,8 +157,8 @@ struct PipelineBaton {
|
|||||||
cropOffsetLeft(0),
|
cropOffsetLeft(0),
|
||||||
cropOffsetTop(0),
|
cropOffsetTop(0),
|
||||||
premultiplied(false),
|
premultiplied(false),
|
||||||
tintA(0.0),
|
tintA(128.0),
|
||||||
tintB(0.0),
|
tintB(128.0),
|
||||||
flatten(false),
|
flatten(false),
|
||||||
negate(false),
|
negate(false),
|
||||||
blurSigma(0.0),
|
blurSigma(0.0),
|
||||||
|
|||||||
BIN
test/fixtures/expected/tint-blue.jpg
vendored
Normal file
BIN
test/fixtures/expected/tint-blue.jpg
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
BIN
test/fixtures/expected/tint-cmyk.jpg
vendored
Normal file
BIN
test/fixtures/expected/tint-cmyk.jpg
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 26 KiB |
BIN
test/fixtures/expected/tint-green.jpg
vendored
Normal file
BIN
test/fixtures/expected/tint-green.jpg
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
@@ -19,6 +19,32 @@ describe('Tint', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('tints rgb image green', function (done) {
|
||||||
|
const output = fixtures.path('output.tint-green.jpg');
|
||||||
|
sharp(fixtures.inputJpg)
|
||||||
|
.resize(320, 240)
|
||||||
|
.tint('#00FF00')
|
||||||
|
.toFile(output, function (err, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(true, info.size > 0);
|
||||||
|
fixtures.assertMaxColourDistance(output, fixtures.expected('tint-green.jpg'), 10);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('tints rgb image blue', function (done) {
|
||||||
|
const output = fixtures.path('output.tint-blue.jpg');
|
||||||
|
sharp(fixtures.inputJpg)
|
||||||
|
.resize(320, 240)
|
||||||
|
.tint('#0000FF')
|
||||||
|
.toFile(output, function (err, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(true, info.size > 0);
|
||||||
|
fixtures.assertMaxColourDistance(output, fixtures.expected('tint-blue.jpg'), 10);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('tints rgb image with sepia tone', function (done) {
|
it('tints rgb image with sepia tone', function (done) {
|
||||||
const output = fixtures.path('output.tint-sepia.jpg');
|
const output = fixtures.path('output.tint-sepia.jpg');
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
@@ -60,4 +86,17 @@ describe('Tint', function () {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('tints cmyk image red', function (done) {
|
||||||
|
const output = fixtures.path('output.tint-cmyk.jpg');
|
||||||
|
sharp(fixtures.inputJpgWithCmykProfile)
|
||||||
|
.resize(320, 240)
|
||||||
|
.tint('#FF0000')
|
||||||
|
.toFile(output, function (err, info) {
|
||||||
|
if (err) throw err;
|
||||||
|
assert.strictEqual(true, info.size > 0);
|
||||||
|
fixtures.assertMaxColourDistance(output, fixtures.expected('tint-cmyk.jpg'), 10);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user