mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 15:25:07 +01:00
Add gravity support to embed feature (#1038)
This commit is contained in:
committed by
Lovell Fuller
parent
1d7a0ea99e
commit
927b77700d
@@ -179,11 +179,26 @@ function crop (crop) {
|
||||
* // outputBuffer contains WebP image data of a 200 pixels wide and 300 pixels high
|
||||
* // containing a scaled version, embedded on a transparent canvas, of input.gif
|
||||
* });
|
||||
*
|
||||
* @param {String} [embed='centre'] - A member of `sharp.gravity` to embed to an edge/corner.
|
||||
* @returns {Sharp}
|
||||
* @throws {Error} Invalid parameters
|
||||
*/
|
||||
function embed () {
|
||||
function embed (embed) {
|
||||
this.options.canvas = 'embed';
|
||||
|
||||
if (!is.defined(embed)) {
|
||||
// Default
|
||||
this.options.embed = gravity.center;
|
||||
} else if (is.integer(embed) && is.inRange(embed, 0, 8)) {
|
||||
// Gravity (numeric)
|
||||
this.options.embed = embed;
|
||||
} else if (is.string(embed) && is.integer(gravity[embed])) {
|
||||
// Gravity (string)
|
||||
this.options.embed = gravity[embed];
|
||||
} else {
|
||||
throw is.invalidParameterError('embed', 'valid embed id/name', embed);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user