# Image Processing and return

**URL:** <https://discourse.slimframework.com/t/image-processing-and-return/4742>\
**Category:** Questions\
**Created:** [April 4, 2021, 11:44pm UTC](https://discourse.slimframework.com/t/image-processing-and-return/4742 "2021-04-04T23:44:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![taylorren](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/taylorren/32/1317_2.png) [@taylorren](https://discourse.slimframework.com/u/taylorren)\
**Post date:** [April 4, 2021, 11:44pm UTC](https://discourse.slimframework.com/t/image-processing-and-return/4742/1 "2021-04-04T23:44:22Z")

</div>

I used the latest Slim framework to develop an API backend for my frontend website. All is well, except one.

I use the API backend to process an image before it goes back to the frontend:

```auto
<?php

declare(strict_types=1);

namespace App\Application\Actions\Book;

use Psr\Http\Message\ResponseInterface as Response;

class ImageAction extends BookAction {

    /**
     * {@inheritdoc}
     */
    protected function action(): Response {
        $id = $this->resolveArg('bookid');
        ....
        imagecopyresized($nimg, $oimg, 0, 0, 0, 0, $nw, $nh, $w, $h);
        
        imagedestroy($oimg);

        //header('Content-type: image/png');
        imagepng($nimg);
        imagedestroy($nimg);

        return $this->respondWithData($nimg);
         
    }

}

```

In short, this action put some text on the original image and resize it and return the image.

The problem I have now is that this reponse seems not holding the CORS header - the CORS header is in other JSON-responses.

Thanks!

---

<div class="post-metadata">

**Author:** ![odan](https://avatars.discourse-cdn.com/v4/letter/o/9de053/32.png) [@odan](https://discourse.slimframework.com/u/odan)\
**Post date:** [April 5, 2021, 9:00am UTC](https://discourse.slimframework.com/t/image-processing-and-return/4742/2 "2021-04-05T09:00:08Z")

</div>

You have to fetch the image data from the output buffer with `ob_start();` and `ob_get_clean()`. [Example](https://odan.github.io/2020/05/07/slim4-working-with-images.html#creating-images-using-the-gd-and-image-functions)
