resize.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. /*!
  2. Copyright 2013 Lovell Fuller and others.
  3. SPDX-License-Identifier: Apache-2.0
  4. */
  5. const is = require('./is');
  6. /**
  7. * Weighting to apply when using contain/cover fit.
  8. * @member
  9. * @private
  10. */
  11. const gravity = {
  12. center: 0,
  13. centre: 0,
  14. north: 1,
  15. east: 2,
  16. south: 3,
  17. west: 4,
  18. northeast: 5,
  19. southeast: 6,
  20. southwest: 7,
  21. northwest: 8
  22. };
  23. /**
  24. * Position to apply when using contain/cover fit.
  25. * @member
  26. * @private
  27. */
  28. const position = {
  29. top: 1,
  30. right: 2,
  31. bottom: 3,
  32. left: 4,
  33. 'right top': 5,
  34. 'right bottom': 6,
  35. 'left bottom': 7,
  36. 'left top': 8
  37. };
  38. /**
  39. * How to extend the image.
  40. * @member
  41. * @private
  42. */
  43. const extendWith = {
  44. background: 'background',
  45. copy: 'copy',
  46. repeat: 'repeat',
  47. mirror: 'mirror'
  48. };
  49. /**
  50. * Strategies for automagic cover behaviour.
  51. * @member
  52. * @private
  53. */
  54. const strategy = {
  55. entropy: 16,
  56. attention: 17
  57. };
  58. /**
  59. * Reduction kernels.
  60. * @member
  61. * @private
  62. */
  63. const kernel = {
  64. nearest: 'nearest',
  65. linear: 'linear',
  66. cubic: 'cubic',
  67. mitchell: 'mitchell',
  68. lanczos2: 'lanczos2',
  69. lanczos3: 'lanczos3',
  70. mks2013: 'mks2013',
  71. mks2021: 'mks2021'
  72. };
  73. /**
  74. * Methods by which an image can be resized to fit the provided dimensions.
  75. * @member
  76. * @private
  77. */
  78. const fit = {
  79. contain: 'contain',
  80. cover: 'cover',
  81. fill: 'fill',
  82. inside: 'inside',
  83. outside: 'outside'
  84. };
  85. /**
  86. * Map external fit property to internal canvas property.
  87. * @member
  88. * @private
  89. */
  90. const mapFitToCanvas = {
  91. contain: 'embed',
  92. cover: 'crop',
  93. fill: 'ignore_aspect',
  94. inside: 'max',
  95. outside: 'min'
  96. };
  97. /**
  98. * @private
  99. */
  100. function isRotationExpected (options) {
  101. return (options.angle % 360) !== 0 || options.rotationAngle !== 0;
  102. }
  103. /**
  104. * @private
  105. */
  106. function isResizeExpected (options) {
  107. return options.width !== -1 || options.height !== -1;
  108. }
  109. /**
  110. * Resize image to `width`, `height` or `width x height`.
  111. *
  112. * When both a `width` and `height` are provided, the possible methods by which the image should **fit** these are:
  113. * - `cover`: (default) Preserving aspect ratio, attempt to ensure the image covers both provided dimensions by cropping/clipping to fit.
  114. * - `contain`: Preserving aspect ratio, contain within both provided dimensions using "letterboxing" where necessary.
  115. * - `fill`: Ignore the aspect ratio of the input and stretch to both provided dimensions.
  116. * - `inside`: Preserving aspect ratio, resize the image to be as large as possible while ensuring its dimensions are less than or equal to both those specified.
  117. * - `outside`: Preserving aspect ratio, resize the image to be as small as possible while ensuring its dimensions are greater than or equal to both those specified.
  118. *
  119. * Some of these values are based on the [object-fit](https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit) CSS property.
  120. *
  121. * <img alt="Examples of various values for the fit property when resizing" width="100%" style="aspect-ratio: 998/243" src="/api-resize-fit.svg">
  122. *
  123. * When using a **fit** of `cover` or `contain`, the default **position** is `centre`. Other options are:
  124. * - `sharp.position`: `top`, `right top`, `right`, `right bottom`, `bottom`, `left bottom`, `left`, `left top`.
  125. * - `sharp.gravity`: `north`, `northeast`, `east`, `southeast`, `south`, `southwest`, `west`, `northwest`, `center` or `centre`.
  126. * - `sharp.strategy`: `cover` only, dynamically crop using either the `entropy` or `attention` strategy.
  127. *
  128. * Some of these values are based on the [object-position](https://developer.mozilla.org/en-US/docs/Web/CSS/object-position) CSS property.
  129. *
  130. * The strategy-based approach initially resizes so one dimension is at its target length
  131. * then repeatedly ranks edge regions, discarding the edge with the lowest score based on the selected strategy.
  132. * - `entropy`: focus on the region with the highest [Shannon entropy](https://en.wikipedia.org/wiki/Entropy_%28information_theory%29).
  133. * - `attention`: focus on the region with the highest luminance frequency, colour saturation and presence of skin tones.
  134. *
  135. * Possible downsizing kernels are:
  136. * - `nearest`: Use [nearest neighbour interpolation](http://en.wikipedia.org/wiki/Nearest-neighbor_interpolation).
  137. * - `linear`: Use a [triangle filter](https://en.wikipedia.org/wiki/Triangular_function).
  138. * - `cubic`: Use a [Catmull-Rom spline](https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline).
  139. * - `mitchell`: Use a [Mitchell-Netravali spline](https://www.cs.utexas.edu/~fussell/courses/cs384g-fall2013/lectures/mitchell/Mitchell.pdf).
  140. * - `lanczos2`: Use a [Lanczos kernel](https://en.wikipedia.org/wiki/Lanczos_resampling#Lanczos_kernel) with `a=2`.
  141. * - `lanczos3`: Use a Lanczos kernel with `a=3` (the default).
  142. * - `mks2013`: Use a [Magic Kernel Sharp](https://johncostella.com/magic/mks.pdf) 2013 kernel, as adopted by Facebook.
  143. * - `mks2021`: Use a Magic Kernel Sharp 2021 kernel, with more accurate (reduced) sharpening than the 2013 version.
  144. *
  145. * When upsampling, these kernels map to `nearest`, `linear` and `cubic` interpolators.
  146. * Downsampling kernels without a matching upsampling interpolator map to `cubic`.
  147. *
  148. * Only one resize can occur per pipeline.
  149. * Previous calls to `resize` in the same pipeline will be ignored.
  150. *
  151. * @example
  152. * sharp(input)
  153. * .resize({ width: 100 })
  154. * .toBuffer()
  155. * .then(data => {
  156. * // 100 pixels wide, auto-scaled height
  157. * });
  158. *
  159. * @example
  160. * sharp(input)
  161. * .resize({ height: 100 })
  162. * .toBuffer()
  163. * .then(data => {
  164. * // 100 pixels high, auto-scaled width
  165. * });
  166. *
  167. * @example
  168. * sharp(input)
  169. * .resize(200, 300, {
  170. * kernel: sharp.kernel.nearest,
  171. * fit: 'contain',
  172. * position: 'right top',
  173. * background: { r: 255, g: 255, b: 255, alpha: 0.5 }
  174. * })
  175. * .toFile('output.png')
  176. * .then(() => {
  177. * // output.png is a 200 pixels wide and 300 pixels high image
  178. * // containing a nearest-neighbour scaled version
  179. * // contained within the north-east corner of a semi-transparent white canvas
  180. * });
  181. *
  182. * @example
  183. * const transformer = sharp()
  184. * .resize({
  185. * width: 200,
  186. * height: 200,
  187. * fit: sharp.fit.cover,
  188. * position: sharp.strategy.entropy
  189. * });
  190. * // Read image data from readableStream
  191. * // Write 200px square auto-cropped image data to writableStream
  192. * readableStream
  193. * .pipe(transformer)
  194. * .pipe(writableStream);
  195. *
  196. * @example
  197. * sharp(input)
  198. * .resize(200, 200, {
  199. * fit: sharp.fit.inside,
  200. * withoutEnlargement: true
  201. * })
  202. * .toFormat('jpeg')
  203. * .toBuffer()
  204. * .then(function(outputBuffer) {
  205. * // outputBuffer contains JPEG image data
  206. * // no wider and no higher than 200 pixels
  207. * // and no larger than the input image
  208. * });
  209. *
  210. * @example
  211. * sharp(input)
  212. * .resize(200, 200, {
  213. * fit: sharp.fit.outside,
  214. * withoutReduction: true
  215. * })
  216. * .toFormat('jpeg')
  217. * .toBuffer()
  218. * .then(function(outputBuffer) {
  219. * // outputBuffer contains JPEG image data
  220. * // of at least 200 pixels wide and 200 pixels high while maintaining aspect ratio
  221. * // and no smaller than the input image
  222. * });
  223. *
  224. * @example
  225. * const scaleByHalf = await sharp(input)
  226. * .metadata()
  227. * .then(({ width }) => sharp(input)
  228. * .resize(Math.round(width * 0.5))
  229. * .toBuffer()
  230. * );
  231. *
  232. * @param {number} [width] - How many pixels wide the resultant image should be. Use `null` or `undefined` to auto-scale the width to match the height.
  233. * @param {number} [height] - How many pixels high the resultant image should be. Use `null` or `undefined` to auto-scale the height to match the width.
  234. * @param {Object} [options]
  235. * @param {number} [options.width] - An alternative means of specifying `width`. If both are present this takes priority.
  236. * @param {number} [options.height] - An alternative means of specifying `height`. If both are present this takes priority.
  237. * @param {String} [options.fit='cover'] - How the image should be resized/cropped to fit the target dimension(s), one of `cover`, `contain`, `fill`, `inside` or `outside`.
  238. * @param {String} [options.position='centre'] - A position, gravity or strategy to use when `fit` is `cover` or `contain`.
  239. * @param {String|Object} [options.background={r: 0, g: 0, b: 0, alpha: 1}] - background colour when `fit` is `contain`, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to black without transparency.
  240. * @param {String} [options.kernel='lanczos3'] - The kernel to use for image reduction and the inferred interpolator to use for upsampling. Use the `fastShrinkOnLoad` option to control kernel vs shrink-on-load.
  241. * @param {Boolean} [options.withoutEnlargement=false] - Do not scale up if the width *or* height are already less than the target dimensions, equivalent to GraphicsMagick's `>` geometry option. This may result in output dimensions smaller than the target dimensions.
  242. * @param {Boolean} [options.withoutReduction=false] - Do not scale down if the width *or* height are already greater than the target dimensions, equivalent to GraphicsMagick's `<` geometry option. This may still result in a crop to reach the target dimensions.
  243. * @param {Boolean} [options.fastShrinkOnLoad=true] - Take greater advantage of the JPEG and WebP shrink-on-load feature, which can lead to a slight moiré pattern or round-down of an auto-scaled dimension.
  244. * @returns {Sharp}
  245. * @throws {Error} Invalid parameters
  246. */
  247. function resize (widthOrOptions, height, options) {
  248. if (isResizeExpected(this.options)) {
  249. this.options.debuglog('ignoring previous resize options');
  250. }
  251. if (this.options.widthPost !== -1) {
  252. this.options.debuglog('operation order will be: extract, resize, extract');
  253. }
  254. if (is.defined(widthOrOptions)) {
  255. if (is.object(widthOrOptions) && !is.defined(options)) {
  256. options = widthOrOptions;
  257. } else if (is.integer(widthOrOptions) && widthOrOptions > 0) {
  258. this.options.width = widthOrOptions;
  259. } else {
  260. throw is.invalidParameterError('width', 'positive integer', widthOrOptions);
  261. }
  262. } else {
  263. this.options.width = -1;
  264. }
  265. if (is.defined(height)) {
  266. if (is.integer(height) && height > 0) {
  267. this.options.height = height;
  268. } else {
  269. throw is.invalidParameterError('height', 'positive integer', height);
  270. }
  271. } else {
  272. this.options.height = -1;
  273. }
  274. if (is.object(options)) {
  275. // Width
  276. if (is.defined(options.width)) {
  277. if (is.integer(options.width) && options.width > 0) {
  278. this.options.width = options.width;
  279. } else {
  280. throw is.invalidParameterError('width', 'positive integer', options.width);
  281. }
  282. }
  283. // Height
  284. if (is.defined(options.height)) {
  285. if (is.integer(options.height) && options.height > 0) {
  286. this.options.height = options.height;
  287. } else {
  288. throw is.invalidParameterError('height', 'positive integer', options.height);
  289. }
  290. }
  291. // Fit
  292. if (is.defined(options.fit)) {
  293. const canvas = mapFitToCanvas[options.fit];
  294. if (is.string(canvas)) {
  295. this.options.canvas = canvas;
  296. } else {
  297. throw is.invalidParameterError('fit', 'valid fit', options.fit);
  298. }
  299. }
  300. // Position
  301. if (is.defined(options.position)) {
  302. const pos = is.integer(options.position)
  303. ? options.position
  304. : strategy[options.position] || position[options.position] || gravity[options.position];
  305. if (is.integer(pos) && (is.inRange(pos, 0, 8) || is.inRange(pos, 16, 17))) {
  306. this.options.position = pos;
  307. } else {
  308. throw is.invalidParameterError('position', 'valid position/gravity/strategy', options.position);
  309. }
  310. }
  311. // Background
  312. this._setBackgroundColourOption('resizeBackground', options.background);
  313. // Kernel
  314. if (is.defined(options.kernel)) {
  315. if (is.string(kernel[options.kernel])) {
  316. this.options.kernel = kernel[options.kernel];
  317. } else {
  318. throw is.invalidParameterError('kernel', 'valid kernel name', options.kernel);
  319. }
  320. }
  321. // Without enlargement
  322. if (is.defined(options.withoutEnlargement)) {
  323. this._setBooleanOption('withoutEnlargement', options.withoutEnlargement);
  324. }
  325. // Without reduction
  326. if (is.defined(options.withoutReduction)) {
  327. this._setBooleanOption('withoutReduction', options.withoutReduction);
  328. }
  329. // Shrink on load
  330. if (is.defined(options.fastShrinkOnLoad)) {
  331. this._setBooleanOption('fastShrinkOnLoad', options.fastShrinkOnLoad);
  332. }
  333. }
  334. if (isRotationExpected(this.options) && isResizeExpected(this.options)) {
  335. this.options.rotateBefore = true;
  336. }
  337. return this;
  338. }
  339. /**
  340. * Extend / pad / extrude one or more edges of the image with either
  341. * the provided background colour or pixels derived from the image.
  342. * This operation will always occur after resizing and extraction, if any.
  343. *
  344. * @example
  345. * // Resize to 140 pixels wide, then add 10 transparent pixels
  346. * // to the top, left and right edges and 20 to the bottom edge
  347. * sharp(input)
  348. * .resize(140)
  349. * .extend({
  350. * top: 10,
  351. * bottom: 20,
  352. * left: 10,
  353. * right: 10,
  354. * background: { r: 0, g: 0, b: 0, alpha: 0 }
  355. * })
  356. * ...
  357. *
  358. * @example
  359. * // Add a row of 10 red pixels to the bottom
  360. * sharp(input)
  361. * .extend({
  362. * bottom: 10,
  363. * background: 'red'
  364. * })
  365. * ...
  366. *
  367. * @example
  368. * // Extrude image by 8 pixels to the right, mirroring existing right hand edge
  369. * sharp(input)
  370. * .extend({
  371. * right: 8,
  372. * background: 'mirror'
  373. * })
  374. * ...
  375. *
  376. * @param {(number|Object)} extend - single pixel count to add to all edges or an Object with per-edge counts
  377. * @param {number} [extend.top=0]
  378. * @param {number} [extend.left=0]
  379. * @param {number} [extend.bottom=0]
  380. * @param {number} [extend.right=0]
  381. * @param {String} [extend.extendWith='background'] - populate new pixels using this method, one of: background, copy, repeat, mirror.
  382. * @param {String|Object} [extend.background={r: 0, g: 0, b: 0, alpha: 1}] - background colour, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to black without transparency.
  383. * @returns {Sharp}
  384. * @throws {Error} Invalid parameters
  385. */
  386. function extend (extend) {
  387. if (is.integer(extend) && extend > 0) {
  388. this.options.extendTop = extend;
  389. this.options.extendBottom = extend;
  390. this.options.extendLeft = extend;
  391. this.options.extendRight = extend;
  392. } else if (is.object(extend)) {
  393. if (is.defined(extend.top)) {
  394. if (is.integer(extend.top) && extend.top >= 0) {
  395. this.options.extendTop = extend.top;
  396. } else {
  397. throw is.invalidParameterError('top', 'positive integer', extend.top);
  398. }
  399. }
  400. if (is.defined(extend.bottom)) {
  401. if (is.integer(extend.bottom) && extend.bottom >= 0) {
  402. this.options.extendBottom = extend.bottom;
  403. } else {
  404. throw is.invalidParameterError('bottom', 'positive integer', extend.bottom);
  405. }
  406. }
  407. if (is.defined(extend.left)) {
  408. if (is.integer(extend.left) && extend.left >= 0) {
  409. this.options.extendLeft = extend.left;
  410. } else {
  411. throw is.invalidParameterError('left', 'positive integer', extend.left);
  412. }
  413. }
  414. if (is.defined(extend.right)) {
  415. if (is.integer(extend.right) && extend.right >= 0) {
  416. this.options.extendRight = extend.right;
  417. } else {
  418. throw is.invalidParameterError('right', 'positive integer', extend.right);
  419. }
  420. }
  421. this._setBackgroundColourOption('extendBackground', extend.background);
  422. if (is.defined(extend.extendWith)) {
  423. if (is.string(extendWith[extend.extendWith])) {
  424. this.options.extendWith = extendWith[extend.extendWith];
  425. } else {
  426. throw is.invalidParameterError('extendWith', 'one of: background, copy, repeat, mirror', extend.extendWith);
  427. }
  428. }
  429. } else {
  430. throw is.invalidParameterError('extend', 'integer or object', extend);
  431. }
  432. return this;
  433. }
  434. /**
  435. * Extract/crop a region of the image.
  436. *
  437. * - Use `extract` before `resize` for pre-resize extraction.
  438. * - Use `extract` after `resize` for post-resize extraction.
  439. * - Use `extract` twice and `resize` once for extract-then-resize-then-extract in a fixed operation order.
  440. *
  441. * @example
  442. * sharp(input)
  443. * .extract({ left: left, top: top, width: width, height: height })
  444. * .toFile(output, function(err) {
  445. * // Extract a region of the input image, saving in the same format.
  446. * });
  447. * @example
  448. * sharp(input)
  449. * .extract({ left: leftOffsetPre, top: topOffsetPre, width: widthPre, height: heightPre })
  450. * .resize(width, height)
  451. * .extract({ left: leftOffsetPost, top: topOffsetPost, width: widthPost, height: heightPost })
  452. * .toFile(output, function(err) {
  453. * // Extract a region, resize, then extract from the resized image
  454. * });
  455. *
  456. * @param {Object} options - describes the region to extract using integral pixel values
  457. * @param {number} options.left - zero-indexed offset from left edge
  458. * @param {number} options.top - zero-indexed offset from top edge
  459. * @param {number} options.width - width of region to extract
  460. * @param {number} options.height - height of region to extract
  461. * @returns {Sharp}
  462. * @throws {Error} Invalid parameters
  463. */
  464. function extract (options) {
  465. const suffix = isResizeExpected(this.options) || this.options.widthPre !== -1 ? 'Post' : 'Pre';
  466. if (this.options[`width${suffix}`] !== -1) {
  467. this.options.debuglog('ignoring previous extract options');
  468. }
  469. ['left', 'top', 'width', 'height'].forEach(function (name) {
  470. const value = options[name];
  471. if (is.integer(value) && value >= 0) {
  472. this.options[name + (name === 'left' || name === 'top' ? 'Offset' : '') + suffix] = value;
  473. } else {
  474. throw is.invalidParameterError(name, 'integer', value);
  475. }
  476. }, this);
  477. // Ensure existing rotation occurs before pre-resize extraction
  478. if (isRotationExpected(this.options) && !isResizeExpected(this.options)) {
  479. if (this.options.widthPre === -1 || this.options.widthPost === -1) {
  480. this.options.rotateBefore = true;
  481. }
  482. }
  483. if (this.options.input.autoOrient) {
  484. this.options.orientBefore = true;
  485. }
  486. return this;
  487. }
  488. /**
  489. * Trim pixels from all edges that contain values similar to the given background colour, which defaults to that of the top-left pixel.
  490. *
  491. * Images with an alpha channel will use the combined bounding box of alpha and non-alpha channels.
  492. *
  493. * If the result of this operation would trim an image to nothing then no change is made.
  494. *
  495. * The `info` response Object will contain `trimOffsetLeft` and `trimOffsetTop` properties.
  496. *
  497. * @example
  498. * // Trim pixels with a colour similar to that of the top-left pixel.
  499. * await sharp(input)
  500. * .trim()
  501. * .toFile(output);
  502. *
  503. * @example
  504. * // Trim pixels with the exact same colour as that of the top-left pixel.
  505. * await sharp(input)
  506. * .trim({
  507. * threshold: 0
  508. * })
  509. * .toFile(output);
  510. *
  511. * @example
  512. * // Assume input is line art and trim only pixels with a similar colour to red.
  513. * const output = await sharp(input)
  514. * .trim({
  515. * background: "#FF0000",
  516. * lineArt: true
  517. * })
  518. * .toBuffer();
  519. *
  520. * @example
  521. * // Trim all "yellow-ish" pixels, being more lenient with the higher threshold.
  522. * const output = await sharp(input)
  523. * .trim({
  524. * background: "yellow",
  525. * threshold: 42,
  526. * })
  527. * .toBuffer();
  528. *
  529. * @param {Object} [options]
  530. * @param {string|Object} [options.background='top-left pixel'] - Background colour, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to that of the top-left pixel.
  531. * @param {number} [options.threshold=10] - Allowed difference from the above colour, a positive number.
  532. * @param {boolean} [options.lineArt=false] - Does the input more closely resemble line art (e.g. vector) rather than being photographic?
  533. * @returns {Sharp}
  534. * @throws {Error} Invalid parameters
  535. */
  536. function trim (options) {
  537. this.options.trimThreshold = 10;
  538. if (is.defined(options)) {
  539. if (is.object(options)) {
  540. if (is.defined(options.background)) {
  541. this._setBackgroundColourOption('trimBackground', options.background);
  542. }
  543. if (is.defined(options.threshold)) {
  544. if (is.number(options.threshold) && options.threshold >= 0) {
  545. this.options.trimThreshold = options.threshold;
  546. } else {
  547. throw is.invalidParameterError('threshold', 'positive number', options.threshold);
  548. }
  549. }
  550. if (is.defined(options.lineArt)) {
  551. this._setBooleanOption('trimLineArt', options.lineArt);
  552. }
  553. } else {
  554. throw is.invalidParameterError('trim', 'object', options);
  555. }
  556. }
  557. if (isRotationExpected(this.options)) {
  558. this.options.rotateBefore = true;
  559. }
  560. return this;
  561. }
  562. /**
  563. * Decorate the Sharp prototype with resize-related functions.
  564. * @module Sharp
  565. * @private
  566. */
  567. module.exports = (Sharp) => {
  568. Object.assign(Sharp.prototype, {
  569. resize,
  570. extend,
  571. extract,
  572. trim
  573. });
  574. // Class attributes
  575. Sharp.gravity = gravity;
  576. Sharp.strategy = strategy;
  577. Sharp.kernel = kernel;
  578. Sharp.fit = fit;
  579. Sharp.position = position;
  580. };