Comparing version 0.3.1 to 0.3.2
{ | ||
"name": "impro", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"description": "Image processing engine", | ||
@@ -5,0 +5,0 @@ "author": "Andreas Lind <andreaslindpetersen@gmail.com>", |
@@ -15,2 +15,12 @@ const requireOr = require('require-or'); | ||
function patchPreviousCommandArgument(operation, argUpdates, indexInArg) { | ||
operation = { ...operation }; | ||
operation.args = [...operation.args]; | ||
operation.args[indexInArg] = { | ||
...operation.args[indexInArg], | ||
...argUpdates | ||
}; | ||
return operation; | ||
} | ||
const maxDimension = 16384; | ||
@@ -185,19 +195,59 @@ | ||
if (operation.name === 'crop') { | ||
name = 'resize'; | ||
args = [null, null, { fit: 'cover', position: args[0] }]; | ||
const locatedIndex = locatePreviousCommand( | ||
operationsForExecution, | ||
name | ||
'resize' | ||
); | ||
if (locatedIndex > -1) { | ||
let locatedOperation = operationsForExecution[locatedIndex]; | ||
locatedOperation = { | ||
...locatedOperation, | ||
args: locatedOperation.args.concat(args[2]) | ||
}; | ||
const locatedOperation = patchPreviousCommandArgument( | ||
operationsForExecution[locatedIndex], | ||
{ fit: 'cover', position: args[0] }, | ||
2 | ||
); | ||
operationsForExecution[locatedIndex] = locatedOperation; | ||
return; | ||
} else { | ||
name = 'resize'; | ||
args = [null, null, { fit: 'cover', position: args[0] }]; | ||
} | ||
} | ||
// in sharp withoutEnlargement is implemented as options to resize | ||
if (operation.name === 'withoutEnlargement') { | ||
const locatedIndex = locatePreviousCommand( | ||
operationsForExecution, | ||
'resize' | ||
); | ||
if (locatedIndex > -1) { | ||
const locatedOperation = patchPreviousCommandArgument( | ||
operationsForExecution[locatedIndex], | ||
{ fit: 'inside' }, | ||
2 | ||
); | ||
operationsForExecution[locatedIndex] = locatedOperation; | ||
return; | ||
} else { | ||
throw new Error( | ||
'sharp: withoutEnlargement() operation must follow resize' | ||
); | ||
} | ||
} | ||
// in sharp ignoreAspectRatio is implemented as options to resize | ||
if (operation.name === 'ignoreAspectRatio') { | ||
const locatedIndex = locatePreviousCommand( | ||
operationsForExecution, | ||
'resize' | ||
); | ||
if (locatedIndex > -1) { | ||
const locatedOperation = patchPreviousCommandArgument( | ||
operationsForExecution[locatedIndex], | ||
{ fit: 'fill' }, | ||
2 | ||
); | ||
operationsForExecution[locatedIndex] = locatedOperation; | ||
return; | ||
} else { | ||
throw new Error( | ||
'sharp: ignoreAspectRatio() operation must follow resize' | ||
); | ||
} | ||
} | ||
// in sharp quality is implemented as an option to the target type | ||
@@ -210,9 +260,7 @@ if (operation.name === 'quality') { | ||
if (locatedIndex > -1) { | ||
let locatedOperation = operationsForExecution[locatedIndex]; | ||
locatedOperation = { | ||
...locatedOperation, | ||
args: [ | ||
{ ...locatedOperation.args[0], quality: args[0] } | ||
] | ||
}; | ||
const locatedOperation = patchPreviousCommandArgument( | ||
operationsForExecution[locatedIndex], | ||
{ quality: args[0] }, | ||
0 | ||
); | ||
operationsForExecution[locatedIndex] = locatedOperation; | ||
@@ -219,0 +267,0 @@ return; |
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
59982
1503