# Regenerate all thumbnails

**URL:** <https://discourse.getcockpit.com/t/regenerate-all-thumbnails/1219>\
**Category:** Support\
**Created:** [February 14, 2020, 5:25pm UTC](https://discourse.getcockpit.com/t/regenerate-all-thumbnails/1219 "2020-02-14T17:25:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![WillyBrown](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/willybrown/32/454_2.png) [@WillyBrown](https://discourse.getcockpit.com/u/WillyBrown)\
**Post date:** [February 14, 2020, 5:25pm UTC](https://discourse.getcockpit.com/t/regenerate-all-thumbnails/1219/1 "2020-02-14T17:25:23Z")

</div>

I would like to create an addon able to regenerate all thumbs of cockpit instance and register each url in data base associate to each asset.

I solved the second part with a responsive image addon who register thumbs url in each asset object :

`addons/ResponsiveImage/bootstrap`

```php

function responsiveImage(string $assetPath): array
{
    // available sizes
    $widths = [640, 1024, 1440];

    // ...

    // prepare data
    $data = [];

    // map each sizes
    foreach ($widths as $width) {

        // build thumbnail
        $url = cockpit('cockpit')->thumbnail([
            'src' => $assetPath,
            'width' => $width,
        ]);

        // push result in an array
        $data[] = [
            'url' => $url,
            'width' => $width
             // ...
        ];
    }
    return $data;
}

$app->on('cockpit.assets.save', function (&$assets) use ($app) {
    foreach ($assets as &$asset) {
        $asset['thumbs'] = responsiveImage(COCKPIT_DIR . '/storage/uploads' . $asset['path']);
    }
});

```

Now each asset got is own thumbs registered in database object when I upload a new file.  
`cockpit.assets.save` is exectuted when the file is upload but I didn’t find in documentation something about when asset is update for example.

Any suggestion ?
