From b7bbf58624b670b8f7e24a2494b859b8401d0589 Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Mon, 13 Oct 2014 15:41:10 +0100 Subject: [PATCH] Document new extract method --- README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/README.md b/README.md index 29c604fe..dd08e55a 100755 --- a/README.md +++ b/README.md @@ -168,6 +168,22 @@ http.createServer(function(request, response) { // resized to 200 pixels wide, in WebP format ``` +```javascript +sharp(input) + .extract(top, left, width, height) + .toFile(output); + // Extract a region of the input image, saving in the same format. +``` + +```javascript +sharp(input) + .extract(topOffsetPre, leftOffsetPre, widthPre, heightPre) + .resize(width, height) + .extract(topOffsetPost, leftOffsetPost, widthPost, heightPost) + .toFile(output); + // Extract a region, resize, then extract from the resized image +``` + ```javascript sharp(inputBuffer) .resize(200, 300) @@ -255,6 +271,16 @@ Scale output to `width` x `height`. By default, the resized image is cropped to `height` is the Number of pixels high the resultant image should be. Use `null` or `undefined` to auto-scale the height to match the width. +#### extract(top, left, width, height) + +Extract a region of the image. Can be used with or without a `resize` operation. + +`top` and `left` are the offset, in pixels, from the top-left corner. + +`width` and `height` are the dimensions of the extracted image. + +Use `extract` before `resize` for pre-resize extraction. Use `extract` after `resize` for post-resize extraction. Use `extract` before and after for both. + #### crop([gravity]) Crop the resized image to the exact size specified, the default behaviour.