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

# HTTP Responses

## Transform an image into a HTTP response



The easiest way to return an image directly to the users browser, is to output the [response()](https://image.intervention.io/v2/api/response.md) method. It will automatically send HTTP headers according to the currently image and output encoded image data.

#### Sending a HTTP response

```php
// create a new image resource
$img = Image::canvas(800, 600, '#ff0000');

// send HTTP header and output image data
echo $img->response('jpg', 70);
```

#### Sending HTTP responses manually

```php
// create a new image resource
$img = Image::canvas(800, 600, '#ff0000');

// send HTTP header and output image data
header('Content-Type: image/png');
echo $img->encode('png');
```


Read more about HTTP responses in the [api documentation](https://image.intervention.io/v2/api/response.md).

## HTTP responses in Laravel Applications

In Laravel applications it is almost the same thing, apart from that you can return the method's output directly from your route.

#### Sending a HTTP response in Laravel

```php
Route::get('/', function()
{
    $img = Image::canvas(800, 600, '#ff0000');

    return $img->response();
});
```

#### Attaching images to a HTTP response in Laravel Applications

```php
Route::get('/', function()
{
    $img = Image::canvas(800, 600, '#ff0000');

    // create response and add encoded image data
    $response = Response::make($img->encode('png'));

    // set content-type
    $response->header('Content-Type', 'image/png');
    
    // output
    return $response;
});
```

---

## 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)