# Resize Videos
[View original](https://ittybit.com/guides/resize-videos)
## Resize proportionally
If you only provide one of the two dimensions, the video will be resized proportionally.
For example, a [Task](/docs/tasks) with `width: 960` will resize a `1920x1080` input video to `960x540`: the 960 is set by the `width` prop, and the `height` is calculated to maintain the original aspect ratio (960 is 50% of 1920, 50% of 1080 is 540).
```js
const task = await ittybit.tasks.create({
kind: 'video',
url: 'https://ittyb.it/sample.mp4',
width: 960,
});
```
```python
task = ittybit.tasks.create(
kind='video',
url='https://ittyb.it/sample.mp4',
width=960
)
```
```ruby
task = ittybit.tasks.create(
kind: 'video',
url: 'https://ittyb.it/sample.mp4',
width: 960
)
```
```php
$task = $ittybit->tasks->create([
'kind' => 'video',
'url' => 'https://ittyb.it/sample.mp4',
'width' => 960,
]);
```
```go
task, err := ittybit.Tasks.Create(
context.Background(),
&ittybit.TaskCreateParams{
Kind: "video",
URL: "https://ittyb.it/sample.mp4",
Width: 960,
},
)
```
```js
const task = await fetch('https://api.ittybit.com/tasks', {
method: 'POST',
headers: { 'Authorization': `Bearer ${ITTYBIT_API_KEY}` },
body: JSON.stringify({
kind: 'video',
url: 'https://ittyb.it/sample.mp4',
width: 960,
})
})
```
*(See [SDKs](/sdks) for install and initialization steps.)*
***
## Resize to a specific size
If you provide both the `width` and `height` props, the video will be resized to the exact size you specify.
For example, a [Task](/docs/tasks) with `width: 960` and `height: 960` will resize a `1920x1080` input video to `960x960`: both dimensions are set explicitly by the `width` and the `height` props.
```js
const task = await ittybit.tasks.create({
kind: 'video',
url: 'https://ittyb.it/sample.mp4',
width: 960,
height: 960,
});
```
```python
task = ittybit.tasks.create(
kind='video',
url='https://ittyb.it/sample.mp4',
width=960,
height=960
)
```
```ruby
task = ittybit.tasks.create(
kind: 'video',
url: 'https://ittyb.it/sample.mp4',
width: 960,
height: 960
)
```
```php
$task = $ittybit->tasks->create([
'kind' => 'video',
'url' => 'https://ittyb.it/sample.mp4',
'width' => 960,
'height' => 960,
]);
```
```go
task, err := ittybit.Tasks.Create(
context.Background(),
&ittybit.TaskCreateParams{
Kind: "video",
URL: "https://ittyb.it/sample.mp4",
Width: 960,
Height: 960,
},
)
```
```js
const task = await fetch('https://api.ittybit.com/tasks', {
method: 'POST',
headers: { 'Authorization': `Bearer ${ITTYBIT_API_KEY}` },
body: JSON.stringify({
kind: 'video',
url: 'https://ittyb.it/sample.mp4',
width: 960,
height: 960,
})
})
```
***
## Control how the video is resized
In the previous examples, the video was resized to the exact size you specified, but that may distort the aspect ratio of the video. Making the output video look stretched or squashed.
The `fit` prop allows you to control how the video is resized.
***
### `fit: "cover"`
The video is resized to cover the specified dimensions, while maintaining the original aspect ratio. Any part of the video that does not fit within the specified dimensions will be cropped.
```js
const task = await ittybit.tasks.create({
kind: 'video',
url: 'https://ittyb.it/sample.mp4',
width: 960,
height: 960,
fit: 'cover',
});
```
```python
task = ittybit.tasks.create(
kind='video',
url='https://ittyb.it/sample.mp4',
width=960,
height=960,
fit='cover',
)
```
```ruby
task = ittybit.tasks.create(
kind: 'video',
url: 'https://ittyb.it/sample.mp4',
width: 960,
height: 960,
fit: 'cover',
)
```
```php
$task = $ittybit->tasks->create([
'kind' => 'video',
'url' => 'https://ittyb.it/sample.mp4',
'width' => 960,
'height' => 960,
'fit' => 'cover',
]);
```
```go
task, err := ittybit.Tasks.Create(
context.Background(),
&ittybit.TaskCreateParams{
Kind: "video",
URL: "https://ittyb.it/sample.mp4",
Width: 960,
Height: 960,
Fit: "cover",
},
)
```
```js
const task = await fetch('https://api.ittybit.com/tasks', {
method: 'POST',
headers: { 'Authorization': `Bearer ${ITTYBIT_API_KEY}` },
body: JSON.stringify({
kind: 'video',
url: 'https://ittyb.it/sample.mp4',
width: 960,
height: 960,
fit: 'cover',
})
})
```
***
### `fit: "contain"`
The video is resized to fit within the specified dimensions, while maintaining the original aspect ratio. The video may have extra padding on the top and bottom, or the left and right, depending on the aspect ratio of the input video.
```js
const task = await ittybit.tasks.create({
kind: 'video',
url: 'https://ittyb.it/sample.mp4',
width: 960,
height: 960,
fit: 'contain',
});
```
```python
task = ittybit.tasks.create(
kind='video',
url='https://ittyb.it/sample.mp4',
width=960,
height=960,
fit='contain',
)
```
```ruby
task = ittybit.tasks.create(
kind: 'video',
url: 'https://ittyb.it/sample.mp4',
width: 960,
height: 960,
fit: 'contain',
)
```
```php
$task = $ittybit->tasks->create([
'kind' => 'video',
'url' => 'https://ittyb.it/sample.mp4',
'width' => 960,
'height' => 960,
'fit' => 'contain',
]);
```
```go
task, err := ittybit.Tasks.Create(
context.Background(),
&ittybit.TaskCreateParams{
Kind: "video",
URL: "https://ittyb.it/sample.mp4",
Width: 960,
Height: 960,
Fit: "contain",
},
)
```
```js
const task = await fetch('https://api.ittybit.com/tasks', {
method: 'POST',
headers: { 'Authorization': `Bearer ${ITTYBIT_API_KEY}` },
body: JSON.stringify({
kind: 'video',
url: 'https://ittyb.it/sample.mp4',
width: 960,
height: 960,
fit: 'contain',
})
})
```
***
### `position: ""`
You can use the `position` prop to control where the video is placed within the specified dimensions. For example, to always show the top of the video even when cropping, you can use `position: "top"`.
The available values are:
* `top`
* `top-right`
* `right`
* `bottom-right`
* `bottom`
* `bottom-left`
* `left`
* `top-left`
If you don't specify a position, the video will be centered within the specified dimensions.
```js
const task = await ittybit.tasks.create({
kind: 'video',
url: 'https://ittyb.it/sample.mp4',
width: 960,
height: 960,
fit: 'cover',
position: 'top-left',
});
```
```python
task = ittybit.tasks.create(
kind='video',
url='https://ittyb.it/sample.mp4',
width=960,
height=960,
fit='cover',
position='top-left',
)
```
```ruby
task = ittybit.tasks.create(
kind: 'video',
url: 'https://ittyb.it/sample.mp4',
width: 960,
height: 960,
fit: 'cover',
position: 'top-left',
)
```
```php
$task = $ittybit->tasks->create([
'kind' => 'video',
'url' => 'https://ittyb.it/sample.mp4',
'width' => 960,
'height' => 960,
'fit' => 'cover',
'position' => 'top-left',
]);
```
```go
task, err := ittybit.Tasks.Create(
context.Background(),
&ittybit.TaskCreateParams{
Kind: "video",
URL: "https://ittyb.it/sample.mp4",
Width: 960,
Height: 960,
Fit: "cover",
Position: "top-left",
},
)
```
```js
const task = await fetch('https://api.ittybit.com/tasks', {
method: 'POST',
headers: { 'Authorization': `Bearer ${ITTYBIT_API_KEY}` },
body: JSON.stringify({
kind: 'video',
url: 'https://ittyb.it/sample.mp4',
width: 960,
height: 960,
fit: 'cover',
position: 'top-left',
})
})
```
The `position` prop is also supported for the `contain` fit type. In this case the video will be placed against the specified position and extra padding will be added to the other sides.
***
### `background: ""`
You can use the `background` prop to specify a background color for the video. The background color will be used for any extra padding added to the video when it is resized.
The background color must be a valid hex color e.g. `#000000`, `#ffffff`, or `#bada55`.
```js
const task = await ittybit.tasks.create({
kind: 'video',
url: 'https://ittyb.it/sample.mp4',
width: 960,
height: 960,
fit: 'contain',
position: 'top-left',
background: '#20B075',
});
```
```python
task = ittybit.tasks.create(
kind='video',
url='https://ittyb.it/sample.mp4',
width=960,
height=960,
fit='contain',
position='top-left',
background='#20B075',
)
```
```ruby
task = ittybit.tasks.create(
kind: 'video',
url: 'https://ittyb.it/sample.mp4',
width: 960,
height: 960,
fit: 'contain',
position: 'top-left',
background: '#20B075',
)
```
```php
$task = $ittybit->tasks->create([
'kind' => 'video',
'url' => 'https://ittyb.it/sample.mp4',
'width' => 960,
'height' => 960,
'fit' => 'contain',
'position' => 'top-left',
'background' => '#20B075',
]);
```
```go
task, err := ittybit.Tasks.Create(
context.Background(),
&ittybit.TaskCreateParams{
Kind: "video",
URL: "https://ittyb.it/sample.mp4",
Width: 960,
Height: 960,
Fit: "contain",
Position: "top-left",
Background: "#20B075",
},
)
```
```js
const task = await fetch('https://api.ittybit.com/tasks', {
method: 'POST',
headers: { 'Authorization': `Bearer ${ITTYBIT_API_KEY}` },
body: JSON.stringify({
kind: 'video',
url: 'https://ittyb.it/sample.mp4',
width: 960,
height: 960,
fit: 'contain',
position: 'top-left',
background: '#20B075',
})
})
```
Only the `contain` fit type supports the `background` prop. You can include it without raising type errors, but it will be ignored.