# Reference: framescript/image

What a scene imports from `framescript/image` and calls, in the order the module exports it. Each entry has its signature, what it does, and the examples that use it; the types its signatures name are [at the end](#types).

Explained in [Images](/docs/framework/objects/images.md).

## `image`

```ts
function image(texture: Texture, options?: ImageOptions): ImageObject
```

Makes a plane that shows a picture, to pass to `add`. Its size comes from the picture's pixels, so a screenshot keeps its proportions: `image(yield* load.texture("/shot.png"), { pixelsPerUnit: 200 })`.

- `texture`: The picture, as `load.texture` gives it.
- `options`: Density, corner radius, region and filtering.
- Returns: The plane.

Examples: composing/components, components/Badge, loading/assets

## `pictureSize`

```ts
function pictureSize(texture: Texture): PixelSize
```

The size of a texture's picture in pixels.

- `texture`: A texture whose picture has loaded.
- Returns: The width and height, or zeros when there is no picture.

Examples: images/picture

## `sharpen`

```ts
function sharpen(texture: Texture): void
```

Sets a texture up to stay sharp when it is drawn smaller or at an angle: mipmaps, smooth filtering between them, and the sRGB colour space pictures are stored in. A texture that is already set up is left alone, so it is not sent to the graphics card again, and so is a compressed one, such as a `.ktx2` file's: it carries its own mipmaps and colour space, and the card cannot make mipmaps of it.

- `texture`: The texture to set up.

Examples: images/picture

## `imageSize`

```ts
function imageSize(
  picture: PixelSize,
  pixelsPerUnit: number,
  region?: ImageRegion
): PixelSize
```

The size of a plane that shows a picture, or a region of it, at a given density.

- `picture`: The picture's size in pixels.
- `pixelsPerUnit`: How many pixels of the picture fill one scene unit.
- `region`: The part of the picture shown. Defaults to all of it.
- Returns: The plane's width and height in world units.

Examples: images/picture

## `regionUv`

```ts
function regionUv(
  picture: PixelSize,
  region?: ImageRegion,
  flipY?: boolean
): UvRect
```

The texture coordinates of a region of a picture.

- `picture`: The picture's size in pixels.
- `region`: The part of the picture shown. Defaults to all of it.
- `flipY`: Whether the texture is stored bottom row first, as textures loaded from image files are. Defaults to true.
- Returns: The coordinates at the plane's left, bottom, right and top edges.

Examples: images/picture

## `playFrames`

```ts
function playFrames(
  target: FrameTarget,
  frames: ReadonlyArray<Texture>,
  options?: PlayFramesOptions
): Step<void>
```

Plays a numbered set of pictures on something that shows a picture, one after the other at a steady rate: the frames of a rendered animation, a sprite. Which picture shows is a function of the time: before the step it is the one the target had, and after it the last.

- `target`: An image, or any mesh whose material has a `map`.
- `frames`: The pictures in order, as `load.sequence` gives them.
- `options`: `{ fps, times }`.
- Returns: A step that ends after the last picture has had its time.

Examples: loading/assets

## Types

### `FrameTarget`

```ts
interface FrameTarget {
  /** The material whose `map` is the picture shown. */
  readonly material: Material | ReadonlyArray<Material>
}
```

### `ImageObject`

```ts
class ImageObject extends PanelObject {
  /** The picture. */
  readonly texture: Texture
  /** The part of the picture shown, in pixels from its top left corner. */
  readonly region: ImageRegion | undefined
  private readonly anisotropy
  /**
   * @param texture - The picture, as `load.texture` gives it.
   * @param options - Density, corner radius, region and filtering.
   */
  constructor(texture: Texture, options?: ImageOptions)
  /**
   * Raises the texture's anisotropy to what was asked for, or to the most
   * the graphics card allows. three.js calls this just before it draws the
   * plane, which is the first moment the renderer is known.
   *
   * @param renderer - The renderer about to draw the plane.
   */
  onBeforeRender(renderer: WebGLRenderer): void
}
```

### `ImageOptions`

```ts
interface ImageOptions {
  /**
   * How many pixels of the picture fill one scene unit. Defaults to 100. A
   * screenshot taken at twice the density of its layout takes twice the
   * number to come out at the layout's size.
   */
  readonly pixelsPerUnit?: number
  /** The corner radius, in world units. Defaults to 0. */
  readonly radius?: number
  /**
   * The part of the picture to show, in pixels from its top left corner.
   * Defaults to all of it. One screenshot can be cut into several planes.
   */
  readonly region?: ImageRegion
  /**
   * How many samples keep the picture sharp when it is seen at an angle.
   * Defaults to the most the graphics card allows.
   */
  readonly anisotropy?: number
  /** Whether the picture's own transparency shows. Defaults to false. */
  readonly transparent?: boolean
  /** How many pieces each corner's arc is made of. Defaults to 12. */
  readonly segments?: number
  /** A material to draw with; the picture becomes its `map`. */
  readonly material?: Material & {
    map: Texture | null
  }
}
```

### `ImageRegion`

```ts
interface ImageRegion {
  /** The left edge, in pixels from the picture's left edge. */
  readonly x: number
  /** The top edge, in pixels from the picture's top edge. */
  readonly y: number
  /** The width, in pixels. */
  readonly width: number
  /** The height, in pixels. */
  readonly height: number
}
```

### `PixelSize`

```ts
interface PixelSize {
  /** The width, in pixels. */
  readonly width: number
  /** The height, in pixels. */
  readonly height: number
}
```

### `PlayFramesOptions`

```ts
interface PlayFramesOptions {
  /** How many pictures a second. Defaults to 24. */
  readonly fps?: number
  /** How many times the sequence is played through. Defaults to 1. */
  readonly times?: number
}
```
