# three.texttexture

> A texture with the drawn text.

Latest version **22.0.0** (published 2019-10-01) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install three.texttexture
pnpm add three.texttexture
yarn add three.texttexture
bun add three.texttexture
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 22.0.0 |
| Published | 2019-10-01 |
| First published | 2017-08-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 8.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 70 |
| Author | Sergej Sintschilin |
| Maintainers | seregpie |
| Keywords | 3d, canvas, class, font, image, material, mesh, plugin, sprite, text, texture, three |

## Links

- npm: https://www.npmjs.com/package/three.texttexture
- Repository: https://github.com/SeregPie/THREE.TextTexture
- Homepage: https://github.com/SeregPie/THREE.TextTexture#readme
- Issues: https://github.com/SeregPie/THREE.TextTexture/issues
- npm.io page: https://npm.io/package/three.texttexture

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 22.0.0 (latest) — 2019-10-01
- 20.0.0 — 2019-04-26
- 19.0.0 — 2019-01-31
- 18.10.24 — 2018-10-24
- 18.8.6 — 2018-08-05
- 18.8.5 — 2018-08-05
- 18.7.14 — 2018-07-13
- 18.7.6 — 2018-07-06
- 18.3.19 — 2018-03-19
- 18.3.3 — 2018-03-03
- 18.1.14 — 2018-01-14
- 17.11.21 — 2017-11-21
- 17.11.5 — 2017-11-05
- 17.10.22 — 2017-10-22
- 17.10.21 — 2017-10-21
- … 2 more at https://npm.io/package/three.texttexture/versions

## README

# THREE.TextTexture

`class THREE.TextTexture extends THREE.Texture`

An instance of `TextTexture` is a texture with the drawn text.

## demo

[Try it out!](https://seregpie.github.io/THREE.TextTexture/)

## setup

### npm

```shell
npm i three.texttexture
```

### es6

```javascript
import TextTexture from 'three.texttexture';
```

### node

```javascript
let TextTexture = require('three.texttexture');
```

### browser

```html
<script src="https://unpkg.com/three"></script>
<script src="https://unpkg.com/three.texttexture"></script>
```

The module is globally available as `THREE.TextTexture`.

## members

### constructor

```
new THREE.TextTexture({
  align: 'center',
  createCanvas() { /*...*/ },
  fillStyle: '#fff',
  fontFamily: 'sans-serif',
  fontSize: 16,
  fontStyle: 'normal',
  fontVariant: 'normal',
  fontWeight: 'normal',
  lineGap: 0.15,
  loadFontFace(family, style, variant, weight) { /*...*/ },
  padding: 0.25,
  strokeStyle: '#000',
  strokeWidth: 0,
  text: '',
})
```

| argument | description |
| ---: | :--- |
| `align` | The horizontal text alignment. Possible values are `'center'`, `'left'` and `'right'`. |
| `createCanvas` | A function to create a new `Canvas` instance. |
| `fillStyle` | The fill color or style. |
| `fontFamily` | The font family. |
| `fontSize` | The font size. |
| `fontStyle` | The font style. |
| `fontVariant` | The font variant. |
| `fontWeight` | The font weight. |
| `lineGap` | The vertical distance between the text lines. The value is relative to the font size. |
| `loadFontFace` | A function to load a font face. |
| `padding` | The space around the text. The value is relative to the font size. |
| `strokeStyle` | The stroke color or style. |
| `strokeWidth` | The stroke width. The value is relative to the font size. |
| `text` | The text. |

```javascript
let texture = new THREE.TextTexture({
  fontFamily: '"Times New Roman", Times, serif',
  fontSize: 32,
  fontStyle: 'italic',
  text: [
    'Twinkle, twinkle, little star,',
    'How I wonder what you are!',
    'Up above the world so high,',
    'Like a diamond in the sky.',
  ].join('\n'),
});
let material = new THREE.SpriteMaterial({
  color: 0xffffbb,
  map: texture,
});
let sprite = new THREE.Sprite(material);
await texture.redraw();
sprite.scale.setX(texture.image.width / texture.image.height).multiplyScalar(10);
scene.add(sprite);
```

### properties

`.text`

---

`.lines`

*read-only*

The text splitted by the newline character.

---

`.fontFamily`

---

`.fontSize`

---

`.fontWeight`

---

`.fontVariant`

---

`.fontStyle`

---

`.fillStyle`

---

`.strokeWidth`

---

`.strokeStyle`

---

`.align`

---

`.lineGap`

---

`.padding`

---

`.createCanvas`

---

`.loadFontFace`

---

Provide a custom `loadFontFace` function to support the older browsers.

```javascript
loadFontFace(family, style, variant, weight) {
  return (new FontFaceObserver(family, {style, weight})).load();
}
```

### methods

`.redraw()`

Returns a `Promise` that resolves when the image is redrawn.

## see also

- [THREE.TextSprite](https://github.com/SeregPie/THREE.TextSprite)

---
_Source: https://npm.io/package/three.texttexture · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
