From d4a1722863cb54fc14af694820191112d0438268 Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Wed, 12 Oct 2016 19:41:49 +0100 Subject: [PATCH] The long-awaited return of code examples to README --- README.md | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/README.md b/README.md index c844bb1f..d6f3a569 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ # sharp +```sh +npm install sharp +``` + The typical use case for this high speed Node.js module is to convert large images in common formats to smaller, web-friendly JPEG, PNG and WebP images of varying dimensions. @@ -16,6 +20,43 @@ rotation, extraction, compositing and gamma correction are available. OS X, Windows (x64), Linux (x64, ARM) systems do not require the installation of any external runtime dependencies. +## Examples + +```javascript +import sharp from 'sharp'; +``` + +```javascript +sharp(inputBuffer) + .resize(320, 240) + .toFile('output.webp', (err, info) => ... ); +``` + +```javascript +sharp('input.jpg') + .rotate() + .resize(200) + .toBuffer() + .then( data => ... ) + .catch( err => ... ); +``` + +```javascript +const roundedCorners = new Buffer( + '' +); + +const roundedCornerResizer = + sharp() + .resize(200, 200) + .overlayWith(roundedCorners, { cutout: true }) + .png(); + +readableStream + .pipe(roundedCornerResizer) + .pipe(writableStream); +``` + [![Test Coverage](https://coveralls.io/repos/lovell/sharp/badge.png?branch=master)](https://coveralls.io/r/lovell/sharp?branch=master) ### Documentation