Skip to content

Commit

Permalink
add text api examples
Browse files Browse the repository at this point in the history
  • Loading branch information
brahima committed Jul 15, 2022
1 parent 4916dc2 commit bd013c7
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
23 changes: 23 additions & 0 deletions docs/api-constructor.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,29 @@ await sharp({
}).toFile('noise.png');
```

```javascript
// Generate an image from text
await sharp({
text: {
text: 'Hello, world!',
width: 400, // max width
height: 300 // max height
}
}).toFile('text_bw.png');
```

```javascript
// Generate a color image from text using pango markup and font
await sharp({
text: {
text: '<span foreground="red">Red!</span><span background="cyan">blue</span>',
font: 'sans'
rgba: true,
dpi: 300
}
}).toFile('text_color.png');
```

* Throws **[Error][17]** Invalid parameters

Returns **[Sharp][18]**
Expand Down
21 changes: 21 additions & 0 deletions lib/constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,27 @@ const debuglog = util.debuglog('sharp');
* }
* }).toFile('noise.png');
*
* @example
* // Generate an image from text
* await sharp({
* text: {
* text: 'Hello, world!',
* width: 400, // max width
* height: 300 // max height
* }
* }).toFile('text_bw.png');
*
* @example
* // Generate a color image from text using pango markup and font
* await sharp({
* text: {
* text: '<span foreground="red">Red!</span><span background="cyan">blue</span>',
* font: 'sans'
* rgba: true,
* dpi: 300
* }
* }).toFile('text_color.png');
*
* @param {(Buffer|Uint8Array|Uint8ClampedArray|Int8Array|Uint16Array|Int16Array|Uint32Array|Int32Array|Float32Array|Float64Array|string)} [input] - if present, can be
* a Buffer / Uint8Array / Uint8ClampedArray containing JPEG, PNG, WebP, AVIF, GIF, SVG or TIFF image data, or
* a TypedArray containing raw pixel image data, or
Expand Down

0 comments on commit bd013c7

Please sign in to comment.