# core/frame (vanilla.js 0.4.0)

> https://vanillapunch.com/docs/vanilla.js/0.4.0/api/core/frame/

Image region.

## Frame extends Object

Image region.

Example: Make a frame from one cell of a sprite sheet

```js
import { ImageAsset, Frame, Rect } from "./build/vanilla.js";

const imageAsset = new ImageAsset();
await imageAsset.load("examples/assets/spritesheet.png");
const image = imageAsset.getImage();
const frame = new Frame(image, Rect.create(200, 0, 200, 200));
const imageRect = frame.getImageRect();
console.log(imageRect.x, imageRect.y, imageRect.width, imageRect.height);
const wholeFrame = new Frame(image);
const wholeRect = wholeFrame.getImageRect();
console.log(wholeRect.width, wholeRect.height);
```

- `constructor(image, rect = null)` (constructor, since 0.0.8): Constructor.
  - `image` HTMLImageElement: Image. (throws if null or undefined)
  - `rect` Rect | null: Region inside the image. (pixels, the whole image if null, not clipped even if it goes outside the image)
- `getImage()` (method, since 0.0.8): Returns the image.
  - returns HTMLImageElement: Image.
- `getImageRect()` (method, since 0.0.9): Returns the image inner region.
  - returns Rect: Region inside the image. (pixels)
