mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 02:30:12 +02:00
Compare commits
3 Commits
01f6cbbaee
...
5374b036f3
Author | SHA1 | Date | |
---|---|---|---|
|
5374b036f3 | ||
|
327a6d2083 | ||
|
751f9992c4 |
@ -1,105 +0,0 @@
|
||||
version: 2.1
|
||||
|
||||
workflows:
|
||||
build:
|
||||
jobs:
|
||||
- linux-arm64-glibc-node-18:
|
||||
filters:
|
||||
tags:
|
||||
only: /^v.*/
|
||||
- linux-arm64-musl-node-18:
|
||||
filters:
|
||||
tags:
|
||||
only: /^v.*/
|
||||
- linux-arm64-glibc-node-20:
|
||||
filters:
|
||||
tags:
|
||||
only: /^v.*/
|
||||
- linux-arm64-musl-node-20:
|
||||
filters:
|
||||
tags:
|
||||
only: /^v.*/
|
||||
|
||||
jobs:
|
||||
linux-arm64-glibc-node-18:
|
||||
resource_class: arm.medium
|
||||
machine:
|
||||
image: ubuntu-2204:current
|
||||
steps:
|
||||
- checkout
|
||||
- run: |
|
||||
sudo docker run -dit --name sharp --volume "${PWD}:/mnt/sharp" --workdir /mnt/sharp arm64v8/debian:bullseye
|
||||
sudo docker exec sharp sh -c "apt-get update && apt-get install -y build-essential git python3 curl fonts-noto-core"
|
||||
sudo docker exec sharp sh -c "mkdir -p /etc/apt/keyrings"
|
||||
sudo docker exec sharp sh -c "curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg"
|
||||
sudo docker exec sharp sh -c "echo 'deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x nodistro main' | tee /etc/apt/sources.list.d/nodesource.list"
|
||||
sudo docker exec sharp sh -c "apt-get update && apt-get install -y nodejs"
|
||||
- run: sudo docker exec sharp sh -c "npm install --build-from-source"
|
||||
- run: sudo docker exec sharp sh -c "npm test"
|
||||
- run: |
|
||||
sudo docker exec sharp sh -c "npm run package-from-local-build"
|
||||
sudo docker exec sharp sh -c "npm pkg set \"optionalDependencies.@img/sharp-linux-arm64=file:./npm/linux-arm64\""
|
||||
sudo docker exec sharp sh -c "npm run clean"
|
||||
sudo docker exec sharp sh -c "npm install --ignore-scripts"
|
||||
sudo docker exec sharp sh -c "npm test"
|
||||
- run: "[[ -n $CIRCLE_TAG ]] && sudo docker exec --env prebuild_upload sharp sh -c \"cd src && ln -s ../package.json && npx prebuild --upload=$prebuild_upload\" || true"
|
||||
linux-arm64-glibc-node-20:
|
||||
resource_class: arm.medium
|
||||
machine:
|
||||
image: ubuntu-2204:current
|
||||
steps:
|
||||
- checkout
|
||||
- run: |
|
||||
sudo docker run -dit --name sharp --workdir /mnt/sharp arm64v8/debian:bullseye
|
||||
sudo docker exec sharp sh -c "apt-get update && apt-get install -y build-essential git python3 curl fonts-noto-core"
|
||||
sudo docker exec sharp sh -c "mkdir -p /etc/apt/keyrings"
|
||||
sudo docker exec sharp sh -c "curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg"
|
||||
sudo docker exec sharp sh -c "echo 'deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main' | tee /etc/apt/sources.list.d/nodesource.list"
|
||||
sudo docker exec sharp sh -c "apt-get update && apt-get install -y nodejs"
|
||||
sudo docker exec sharp sh -c "mkdir -p /mnt/sharp"
|
||||
sudo docker cp . sharp:/mnt/sharp/.
|
||||
- run: sudo docker exec sharp sh -c "npm install --build-from-source"
|
||||
- run: sudo docker exec sharp sh -c "npm test"
|
||||
- run: |
|
||||
sudo docker exec sharp sh -c "npm run package-from-local-build"
|
||||
sudo docker exec sharp sh -c "npm pkg set \"optionalDependencies.@img/sharp-linux-arm64=file:./npm/linux-arm64\""
|
||||
sudo docker exec sharp sh -c "npm run clean"
|
||||
sudo docker exec sharp sh -c "npm install --ignore-scripts"
|
||||
sudo docker exec sharp sh -c "npm test"
|
||||
linux-arm64-musl-node-18:
|
||||
resource_class: arm.medium
|
||||
machine:
|
||||
image: ubuntu-2204:current
|
||||
steps:
|
||||
- checkout
|
||||
- run: |
|
||||
sudo docker run -dit --name sharp --volume "${PWD}:/mnt/sharp" --workdir /mnt/sharp node:18-alpine3.17
|
||||
sudo docker exec sharp sh -c "apk add build-base git python3 font-noto --update-cache"
|
||||
- run: sudo docker exec sharp sh -c "npm install --build-from-source"
|
||||
- run: sudo docker exec sharp sh -c "npm test"
|
||||
- run: |
|
||||
sudo docker exec sharp sh -c "npm run package-from-local-build"
|
||||
sudo docker exec sharp sh -c "npm pkg set \"optionalDependencies.@img/sharp-linuxmusl-arm64=file:./npm/linuxmusl-arm64\""
|
||||
sudo docker exec sharp sh -c "npm run clean"
|
||||
sudo docker exec sharp sh -c "npm install --ignore-scripts"
|
||||
sudo docker exec sharp sh -c "npm test"
|
||||
- run: "[[ -n $CIRCLE_TAG ]] && sudo docker exec --env prebuild_upload sharp sh -c \"cd src && ln -s ../package.json && npx prebuild --upload=$prebuild_upload\" || true"
|
||||
linux-arm64-musl-node-20:
|
||||
resource_class: arm.medium
|
||||
machine:
|
||||
image: ubuntu-2204:current
|
||||
steps:
|
||||
- checkout
|
||||
- run: |
|
||||
sudo docker run -dit --name sharp --workdir /mnt/sharp node:20-alpine3.18
|
||||
sudo docker exec sharp sh -c "apk add build-base git python3 font-noto --update-cache"
|
||||
sudo docker exec sharp sh -c "mkdir -p /mnt/sharp"
|
||||
sudo docker cp . sharp:/mnt/sharp/.
|
||||
- run: sudo docker exec sharp sh -c "npm install --build-from-source"
|
||||
- run: sudo docker exec sharp sh -c "npm test"
|
||||
- run: |
|
||||
sudo docker exec sharp sh -c "npm run package-from-local-build"
|
||||
sudo docker exec sharp sh -c "npm pkg set \"optionalDependencies.@img/sharp-linuxmusl-arm64=file:./npm/linuxmusl-arm64\""
|
||||
sudo docker exec sharp sh -c "npm run clean"
|
||||
sudo docker exec sharp sh -c "npm install --ignore-scripts"
|
||||
sudo docker exec sharp sh -c "npm test"
|
@ -1,5 +1,5 @@
|
||||
freebsd_instance:
|
||||
image_family: freebsd-14-0-snap
|
||||
image_family: freebsd-15-0-snap
|
||||
|
||||
task:
|
||||
name: FreeBSD
|
||||
|
37
.github/workflows/ci.yml
vendored
37
.github/workflows/ci.yml
vendored
@ -9,7 +9,10 @@ jobs:
|
||||
contents: write
|
||||
name: ${{ matrix.platform }} - Node.js ${{ matrix.nodejs_version_major }} ${{ matrix.prebuild && '- prebuild' }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
container: ${{ matrix.container }}
|
||||
container:
|
||||
image: ${{ matrix.container }}
|
||||
volumes:
|
||||
- /:/host
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
@ -46,6 +49,28 @@ jobs:
|
||||
container: node:22-alpine3.20
|
||||
nodejs_version_major: 22
|
||||
platform: linuxmusl-x64
|
||||
- os: ubuntu-24.04-arm
|
||||
container: arm64v8/rockylinux:8
|
||||
nodejs_arch: arm64
|
||||
nodejs_version: "^18.17.0"
|
||||
nodejs_version_major: 18
|
||||
platform: linux-arm64
|
||||
prebuild: true
|
||||
- os: ubuntu-24.04-arm
|
||||
container: arm64v8/rockylinux:8
|
||||
nodejs_arch: arm64
|
||||
nodejs_version: "^20.3.0"
|
||||
nodejs_version_major: 20
|
||||
platform: linux-arm64
|
||||
- os: ubuntu-24.04-arm
|
||||
container: node:18-alpine3.17
|
||||
nodejs_version_major: 18
|
||||
platform: linuxmusl-arm64
|
||||
prebuild: true
|
||||
- os: ubuntu-24.04-arm
|
||||
container: node:20-alpine3.18
|
||||
nodejs_version_major: 20
|
||||
platform: linuxmusl-arm64
|
||||
- os: macos-13
|
||||
nodejs_arch: x64
|
||||
nodejs_version: "^18.17.0"
|
||||
@ -122,6 +147,16 @@ jobs:
|
||||
nodejs_version_major: 22
|
||||
platform: win32-arm64
|
||||
steps:
|
||||
- name: Allow Linux musl containers on ARM64 runners # https://github.com/actions/runner/issues/801#issuecomment-2394425757
|
||||
if: matrix.platform == 'linuxmusl-arm64'
|
||||
shell: sh
|
||||
run: |
|
||||
apk add nodejs
|
||||
sed -i "s:ID=alpine:ID=NotpineForGHA:" /etc/os-release
|
||||
cd /host/home/runner/runners/*/externals/
|
||||
rm -rf node20/*
|
||||
mkdir node20/bin
|
||||
ln -s /usr/bin/node node20/bin/node
|
||||
- name: Dependencies (Rocky Linux glibc)
|
||||
if: contains(matrix.container, 'rockylinux')
|
||||
run: |
|
||||
|
@ -47,6 +47,7 @@ where the overall height is the `pageHeight` multiplied by the number of `pages`
|
||||
| [options.subifd] | <code>number</code> | <code>-1</code> | subIFD (Sub Image File Directory) to extract for OME-TIFF, defaults to main image. |
|
||||
| [options.level] | <code>number</code> | <code>0</code> | level to extract from a multi-level input (OpenSlide), zero based. |
|
||||
| [options.pdfBackground] | <code>string</code> \| <code>Object</code> | | Background colour to use when PDF is partially transparent. Parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha. Requires the use of a globally-installed libvips compiled with support for PDFium, Poppler, ImageMagick or GraphicsMagick. |
|
||||
| [options.jp2Oneshot] | <code>boolean</code> | <code>false</code> | Set to `true` to decode tiled JPEG 2000 images in a single operation, improving compatibility. |
|
||||
| [options.animated] | <code>boolean</code> | <code>false</code> | Set to `true` to read all frames/pages of an animated image (GIF, WebP, TIFF), equivalent of setting `pages` to `-1`. |
|
||||
| [options.raw] | <code>Object</code> | | describes raw pixel input image data. See `raw()` for pixel ordering. |
|
||||
| [options.raw.width] | <code>number</code> | | integral number of pixels wide. |
|
||||
|
@ -10,6 +10,10 @@ Requires libvips v8.17.0
|
||||
|
||||
* Upgrade to libvips v8.17.0 for upstream bug fixes.
|
||||
|
||||
* Expose JPEG 2000 `oneshot` decoder option.
|
||||
[#4262](https://github.com/lovell/sharp/pull/4262)
|
||||
[@mbklein](https://github.com/mbklein)
|
||||
|
||||
* Support composite operation with non-sRGB pipeline colourspace.
|
||||
[#4412](https://github.com/lovell/sharp/pull/4412)
|
||||
[@kleisauke](https://github.com/kleisauke)
|
||||
|
@ -175,7 +175,7 @@ The default memory allocator on most glibc-based Linux systems
|
||||
processes that involve lots of small memory allocations.
|
||||
|
||||
For this reason, by default, sharp will limit the use of thread-based
|
||||
[concurrency](api-utility#concurrency) when the glibc allocator is
|
||||
[concurrency](/api-utility#concurrency) when the glibc allocator is
|
||||
detected at runtime.
|
||||
|
||||
To help avoid fragmentation and improve performance on these systems,
|
||||
|
@ -156,6 +156,7 @@ const debuglog = util.debuglog('sharp');
|
||||
* @param {number} [options.subifd=-1] - subIFD (Sub Image File Directory) to extract for OME-TIFF, defaults to main image.
|
||||
* @param {number} [options.level=0] - level to extract from a multi-level input (OpenSlide), zero based.
|
||||
* @param {string|Object} [options.pdfBackground] - Background colour to use when PDF is partially transparent. Parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha. Requires the use of a globally-installed libvips compiled with support for PDFium, Poppler, ImageMagick or GraphicsMagick.
|
||||
* @param {boolean} [options.jp2Oneshot=false] - Set to `true` to decode tiled JPEG 2000 images in a single operation, improving compatibility.
|
||||
* @param {boolean} [options.animated=false] - Set to `true` to read all frames/pages of an animated image (GIF, WebP, TIFF), equivalent of setting `pages` to `-1`.
|
||||
* @param {Object} [options.raw] - describes raw pixel input image data. See `raw()` for pixel ordering.
|
||||
* @param {number} [options.raw.width] - integral number of pixels wide.
|
||||
|
2
lib/index.d.ts
vendored
2
lib/index.d.ts
vendored
@ -1009,6 +1009,8 @@ declare namespace sharp {
|
||||
level?: number | undefined;
|
||||
/** Background colour to use when PDF is partially transparent. Requires the use of a globally-installed libvips compiled with support for PDFium, Poppler, ImageMagick or GraphicsMagick. */
|
||||
pdfBackground?: Colour | Color | undefined;
|
||||
/** Set to `true` to load JPEG 2000 images using [oneshot mode](https://github.com/libvips/libvips/issues/4205) */
|
||||
jp2Oneshot?: boolean | undefined;
|
||||
/** Set to `true` to read all frames/pages of an animated image (equivalent of setting `pages` to `-1`). (optional, default false) */
|
||||
animated?: boolean | undefined;
|
||||
/** Describes raw pixel input image data. See raw() for pixel ordering. */
|
||||
|
14
lib/input.js
14
lib/input.js
@ -27,9 +27,9 @@ const align = {
|
||||
* @private
|
||||
*/
|
||||
function _inputOptionsFromObject (obj) {
|
||||
const { raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd, pdfBackground, autoOrient } = obj;
|
||||
return [raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd, pdfBackground, autoOrient].some(is.defined)
|
||||
? { raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd, pdfBackground, autoOrient }
|
||||
const { raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd, pdfBackground, autoOrient, jp2Oneshot } = obj;
|
||||
return [raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd, pdfBackground, autoOrient, jp2Oneshot].some(is.defined)
|
||||
? { raw, density, limitInputPixels, ignoreIcc, unlimited, sequentialRead, failOn, failOnError, animated, page, pages, subifd, pdfBackground, autoOrient, jp2Oneshot }
|
||||
: undefined;
|
||||
}
|
||||
|
||||
@ -250,6 +250,14 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
|
||||
if (is.defined(inputOptions.pdfBackground)) {
|
||||
inputDescriptor.pdfBackground = this._getBackgroundColourOption(inputOptions.pdfBackground);
|
||||
}
|
||||
// JP2 oneshot
|
||||
if (is.defined(inputOptions.jp2Oneshot)) {
|
||||
if (is.bool(inputOptions.jp2Oneshot)) {
|
||||
inputDescriptor.jp2Oneshot = inputOptions.jp2Oneshot;
|
||||
} else {
|
||||
throw is.invalidParameterError('jp2Oneshot', 'boolean', inputOptions.jp2Oneshot);
|
||||
}
|
||||
}
|
||||
// Create new image
|
||||
if (is.defined(inputOptions.create)) {
|
||||
if (
|
||||
|
@ -113,6 +113,10 @@ namespace sharp {
|
||||
if (HasAttr(input, "pdfBackground")) {
|
||||
descriptor->pdfBackground = AttrAsVectorOfDouble(input, "pdfBackground");
|
||||
}
|
||||
// Use JPEG 2000 oneshot mode?
|
||||
if (HasAttr(input, "jp2Oneshot")) {
|
||||
descriptor->jp2Oneshot = AttrAsBool(input, "jp2Oneshot");
|
||||
}
|
||||
// Create new image
|
||||
if (HasAttr(input, "createChannels")) {
|
||||
descriptor->createChannels = AttrAsUint32(input, "createChannels");
|
||||
@ -434,6 +438,9 @@ namespace sharp {
|
||||
if (imageType == ImageType::PDF) {
|
||||
option->set("background", descriptor->pdfBackground);
|
||||
}
|
||||
if (imageType == ImageType::JP2) {
|
||||
option->set("oneshot", descriptor->jp2Oneshot);
|
||||
}
|
||||
image = VImage::new_from_buffer(descriptor->buffer, descriptor->bufferLength, nullptr, option);
|
||||
if (imageType == ImageType::SVG || imageType == ImageType::PDF || imageType == ImageType::MAGICK) {
|
||||
image = SetDensity(image, descriptor->density);
|
||||
@ -541,6 +548,9 @@ namespace sharp {
|
||||
if (imageType == ImageType::PDF) {
|
||||
option->set("background", descriptor->pdfBackground);
|
||||
}
|
||||
if (imageType == ImageType::JP2) {
|
||||
option->set("oneshot", descriptor->jp2Oneshot);
|
||||
}
|
||||
image = VImage::new_from_file(descriptor->file.data(), option);
|
||||
if (imageType == ImageType::SVG || imageType == ImageType::PDF || imageType == ImageType::MAGICK) {
|
||||
image = SetDensity(image, descriptor->density);
|
||||
|
@ -78,6 +78,7 @@ namespace sharp {
|
||||
VipsAlign joinHalign;
|
||||
VipsAlign joinValign;
|
||||
std::vector<double> pdfBackground;
|
||||
bool jp2Oneshot;
|
||||
|
||||
InputDescriptor():
|
||||
autoOrient(false),
|
||||
@ -120,7 +121,8 @@ namespace sharp {
|
||||
joinBackground{ 0.0, 0.0, 0.0, 255.0 },
|
||||
joinHalign(VIPS_ALIGN_LOW),
|
||||
joinValign(VIPS_ALIGN_LOW),
|
||||
pdfBackground{ 255.0, 255.0, 255.0, 255.0 } {}
|
||||
pdfBackground{ 255.0, 255.0, 255.0, 255.0 },
|
||||
jp2Oneshot(false) {}
|
||||
};
|
||||
|
||||
// Convenience methods to access the attributes of a Napi::Object
|
||||
|
1
test/fixtures/index.js
vendored
1
test/fixtures/index.js
vendored
@ -117,6 +117,7 @@ module.exports = {
|
||||
inputTiffFogra: getPath('fogra-0-100-100-0.tif'), // https://github.com/lovell/sharp/issues/4045
|
||||
|
||||
inputJp2: getPath('relax.jp2'), // https://www.fnordware.com/j2k/relax.jp2
|
||||
inputJp2TileParts: getPath('relax_tileparts.jp2'), // kdu_expand -i relax.jp2 -o relax-tmp.tif ; kdu_compress -i relax-tmp.tif -o relax_tileparts.jp2 -jp2_space sRGB Clayers=8 -rate 1.0,0.04 Stiles='{128,128}' ORGtparts=L ; rm relax-tmp.tif
|
||||
inputGif: getPath('Crash_test.gif'), // http://upload.wikimedia.org/wikipedia/commons/e/e3/Crash_test.gif
|
||||
inputGifGreyPlusAlpha: getPath('grey-plus-alpha.gif'), // http://i.imgur.com/gZ5jlmE.gif
|
||||
inputGifAnimated: getPath('rotating-squares.gif'), // CC0 https://loading.io/spinner/blocks/-rotating-squares-preloader-gif
|
||||
|
BIN
test/fixtures/relax_tileparts.jp2
vendored
Normal file
BIN
test/fixtures/relax_tileparts.jp2
vendored
Normal file
Binary file not shown.
@ -721,6 +721,9 @@ const color: sharp.Color = '#fff';
|
||||
sharp({ pdfBackground: colour });
|
||||
sharp({ pdfBackground: color });
|
||||
|
||||
sharp({ jp2Oneshot: true });
|
||||
sharp({ jp2Oneshot: false });
|
||||
|
||||
sharp({ autoOrient: true });
|
||||
sharp({ autoOrient: false });
|
||||
sharp().autoOrient();
|
||||
|
@ -93,10 +93,38 @@ describe('JP2 output', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid JP2 chromaSubsampling value throws error', function () {
|
||||
assert.throws(function () {
|
||||
sharp().jpeg({ chromaSubsampling: '4:2:2' });
|
||||
it('can use the jp2Oneshot option to handle multi-part tiled JPEG 2000 file', async () => {
|
||||
const outputJpg = fixtures.path('output.jpg');
|
||||
await assert.rejects(
|
||||
() => sharp(fixtures.inputJp2TileParts).toFile(outputJpg)
|
||||
);
|
||||
await assert.doesNotReject(async () => {
|
||||
await sharp(fixtures.inputJp2TileParts, { jp2Oneshot: true }).toFile(outputJpg);
|
||||
const { format, width, height } = await sharp(outputJpg).metadata();
|
||||
assert.strictEqual(format, 'jpeg');
|
||||
assert.strictEqual(width, 320);
|
||||
assert.strictEqual(height, 240);
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid JP2 chromaSubsampling value throws error', () => {
|
||||
assert.throws(
|
||||
() => sharp().jp2({ chromaSubsampling: '4:2:2' }),
|
||||
/Expected one of 4:2:0, 4:4:4 but received 4:2:2 of type string/
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
it('valid JP2 oneshot value does not throw error', () => {
|
||||
assert.doesNotThrow(
|
||||
() => sharp(fixtures.inputJp2TileParts, { jp2Oneshot: true })
|
||||
);
|
||||
});
|
||||
|
||||
it('invalid JP2 oneshot value throws error', () => {
|
||||
assert.throws(
|
||||
() => sharp(fixtures.inputJp2TileParts, { jp2Oneshot: 'fail' }),
|
||||
/Expected boolean for jp2Oneshot but received fail of type string/
|
||||
);
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user