---
application: "Intervention Image"
version: "Version 2"
status: "eol"
---

# Image::resize

## Resize the current image



> public Intervention\Image\Image resize (integer $width, integer $height, Closure $callback)

Resizes current image based on given **width** and/or **height**. To constraint the resize command, pass an optional Closure **callback** as third parameter.
    
### Parameters

#### width
The new width of the image

#### height
The new height of the image

#### callback (optional)

Closure callback defining constraints on the resize. It's possible to constraint the **aspect-ratio** and/or a unwanted **upsizing** of the image. See examples below.

> public Intervention\Image\Size aspectRatio()

Constraint the current aspect-ratio of the image. As a shortcut to proportional resizing you can use [widen()](https://image.intervention.io/v2/api/widen.md) or [heighten()](https://image.intervention.io/v2/api/heighten.md).

> public Intervention\Image\Size upsize()

Keep image from being upsized.

### Return Values
Instance of `Intervention\Image\Image`

### Examples

```php
// create instance
$img = Image::make('public/foo.jpg');

// resize image to fixed size
$img->resize(300, 200);

// resize only the width of the image
$img->resize(300, null);

// resize only the height of the image
$img->resize(null, 200);

// resize the image to a width of 300 and constrain aspect ratio (auto height)
$img->resize(300, null, function ($constraint) {
    $constraint->aspectRatio();
});

// resize the image to a height of 200 and constrain aspect ratio (auto width)
$img->resize(null, 200, function ($constraint) {
    $constraint->aspectRatio();
});

// prevent possible upsizing
$img->resize(null, 400, function ($constraint) {
    $constraint->aspectRatio();
    $constraint->upsize();
});

// resize the image so that the largest side fits within the limit; the smaller
// side will be scaled to maintain the original aspect ratio
$img->resize(400, 400, function ($constraint) {
    $constraint->aspectRatio();
    $constraint->upsize();
});
```

### See also

- [widen](https://image.intervention.io/v2/api/widen.md)
- [heighten](https://image.intervention.io/v2/api/heighten.md)
- [fit](https://image.intervention.io/v2/api/fit.md)
- [resizeCanvas](https://image.intervention.io/v2/api/resize-canvas.md)
- [crop](https://image.intervention.io/v2/api/crop.md)
- [trim](https://image.intervention.io/v2/api/trim.md)

---

## Become a Sponsor

### Intervention Image needs your help to keep the project going

Intervention Image is non-commercial, open source licensed and completely free to use. The considerable
effort required to maintain and develop the software is only possible with the financial support
of sponsors. There are two ways in which you can support this project.

- Support via [GitHub Sponsors](https://github.com/sponsors/Intervention)
- Support via [Ko-Fi](https://ko-fi.com/interventionphp)