mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 18:40:16 +02:00
Add input fileSuffix and output alias to format #2642
This commit is contained in:
parent
8ff33763ce
commit
905518fab0
@ -11,6 +11,9 @@ Requires libvips v8.13.0
|
||||
* Use combined bounding box of alpha and non-alpha channels for `trim` operation.
|
||||
[#2166](https://github.com/lovell/sharp/issues/2166)
|
||||
|
||||
* Add input `fileSuffix` and output `alias` to `format` information.
|
||||
[#2642](https://github.com/lovell/sharp/issues/2642)
|
||||
|
||||
* Re-introduce support for greyscale ICC profiles (temporarily removed in 0.30.2).
|
||||
[#3114](https://github.com/lovell/sharp/issues/3114)
|
||||
|
||||
|
@ -10,6 +10,9 @@ const formats = new Map([
|
||||
['avif', 'avif'],
|
||||
['jpeg', 'jpeg'],
|
||||
['jpg', 'jpeg'],
|
||||
['jpe', 'jpeg'],
|
||||
['tile', 'tile'],
|
||||
['dz', 'tile'],
|
||||
['png', 'png'],
|
||||
['raw', 'raw'],
|
||||
['tiff', 'tiff'],
|
||||
|
@ -17,6 +17,10 @@ const sharp = require('./sharp');
|
||||
* @returns {Object}
|
||||
*/
|
||||
const format = sharp.format();
|
||||
format.heif.output.alias = ['avif', 'heic'];
|
||||
format.jpeg.output.alias = ['jpe', 'jpg'];
|
||||
format.tiff.output.alias = ['tif'];
|
||||
format.jp2k.output.alias = ['j2c', 'j2k', 'jp2', 'jpx'];
|
||||
|
||||
/**
|
||||
* An Object containing the available interpolators and their proper values
|
||||
|
@ -118,14 +118,22 @@ Napi::Value format(const Napi::CallbackInfo& info) {
|
||||
"ppm", "fits", "gif", "svg", "heif", "pdf", "vips", "jp2k"
|
||||
}) {
|
||||
// Input
|
||||
Napi::Boolean hasInputFile =
|
||||
Napi::Boolean::New(env, vips_type_find("VipsOperation", (f + "load").c_str()));
|
||||
const VipsObjectClass *oc = vips_class_find("VipsOperation", (f + "load").c_str());
|
||||
Napi::Boolean hasInputFile = Napi::Boolean::New(env, oc);
|
||||
Napi::Boolean hasInputBuffer =
|
||||
Napi::Boolean::New(env, vips_type_find("VipsOperation", (f + "load_buffer").c_str()));
|
||||
Napi::Object input = Napi::Object::New(env);
|
||||
input.Set("file", hasInputFile);
|
||||
input.Set("buffer", hasInputBuffer);
|
||||
input.Set("stream", hasInputBuffer);
|
||||
if (hasInputFile) {
|
||||
Napi::Array fileSuffix = Napi::Array::New(env);
|
||||
const char **suffix = VIPS_FOREIGN_CLASS(oc)->suffs;
|
||||
for (int i = 0; *suffix; i++, suffix++) {
|
||||
fileSuffix.Set(i, Napi::String::New(env, *suffix));
|
||||
}
|
||||
input.Set("fileSuffix", fileSuffix);
|
||||
}
|
||||
// Output
|
||||
Napi::Boolean hasOutputFile =
|
||||
Napi::Boolean::New(env, vips_type_find("VipsOperation", (f + "save").c_str()));
|
||||
|
@ -102,7 +102,7 @@ describe('Utilities', function () {
|
||||
['input', 'output'].forEach(function (direction) {
|
||||
assert.strictEqual(true, direction in sharp.format[format]);
|
||||
assert.strictEqual('object', typeof sharp.format[format][direction]);
|
||||
assert.strictEqual(3, Object.keys(sharp.format[format][direction]).length);
|
||||
assert.strictEqual(true, [3, 4].includes(Object.keys(sharp.format[format][direction]).length));
|
||||
assert.strictEqual(true, 'file' in sharp.format[format][direction]);
|
||||
assert.strictEqual(true, 'buffer' in sharp.format[format][direction]);
|
||||
assert.strictEqual(true, 'stream' in sharp.format[format][direction]);
|
||||
@ -126,6 +126,12 @@ describe('Utilities', function () {
|
||||
assert.strictEqual(false, sharp.format.vips[direction].stream);
|
||||
});
|
||||
});
|
||||
it('input fileSuffix', function () {
|
||||
assert.deepStrictEqual(['.jpg', '.jpeg', '.jpe'], sharp.format.jpeg.input.fileSuffix);
|
||||
});
|
||||
it('output alias', function () {
|
||||
assert.deepStrictEqual(['jpe', 'jpg'], sharp.format.jpeg.output.alias);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Versions', function () {
|
||||
|
Loading…
x
Reference in New Issue
Block a user