# New Addon: ImageResize

**URL:** https://discourse.getcockpit.com/t/new-addon-imageresize/903
**Category:** Addons
**Created:** [July 2, 2019, 2:56pm UTC](https://discourse.getcockpit.com/t/new-addon-imageresize/903 "2019-07-02T14:56:47Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![raffaelj](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/raffaelj/32/331_2.png) [@raffaelj](https://discourse.getcockpit.com/u/raffaelj)
#### Post date: [July 2, 2019, 2:56pm UTC](https://discourse.getcockpit.com/t/new-addon-imageresize/903/1 "2019-07-02T14:56:47Z")

</div>

I wrote an addon to resize uploaded images automatically. It might share some behavior with [ImageStyles](https://github.com/pauloamgomes/ImageStyles), but I wanted to replace the uploaded images with smaller ones. A client tends to upload giant images and everytime my scripts try to create thumbnails, e. g. after cleaning the cache, it takes ages to process them.

## Addon

> **[GitHub - raffaelj/cockpit\_ImageResize: Addon for Cockpit CMS to resize uploaded images...](https://github.com/raffaelj/cockpit_ImageResize)**
>
> Addon for Cockpit CMS to resize uploaded images automatically

## Related discusson

> [@How to downsize uploaded image assets to max width/height?](https://discourse.getcockpit.com/t/how-to-downsize-uploaded-image-assets-to-max-width-height/883):
>
> Is it possible to automaticaly downsize image assets while uploading to desired max. dimensions (width, height)? Limit uploads by group vars “assets.max\_upload\_size” is not solution in my case. It would be useful to have an config options, somethink like: “assets.max\_image\_width,assets.max\_image\_height”.

## Usage

A copy of the original file is stored in `/uploads/full/filename.jpg`. The default file will be replaced with the resized file. From now on, you don’t have to create thumbnails from 8MB sized files again, but you are still able to use the original file, if you want to.

If users upload very large images, it will take a while to process the files.

There is no option in the assets manager to choose the original file, but your api autput has two additional keys:

**original keys:**

```auto
"path": "/2019/07/02/filename.jpg",
"title": "DSC07504.JPG",
...

```

**extra keys:**

```auto
"sizes": {
    "full": {
        "path": "/full/filename.jpg",
        "width": 4912,
        "height": 3264,
        "size": 4390912
    }
},
"resized": true,

```

## Options

Use the GUI or add options to `/config/config.yaml`.

If you set `maxWidth` or `maxHeight` to `0` (zero), the value will be ignored.

```yaml
imageresize:
    enabled: true # boolean, default: false
    keepOriginal: true # boolean, default: true
    moveOriginalTo: original # string, default: "full"
    maxWidth: 1024 # int, default: 1920
    maxHeight: 1024 # int, default: 0
    method: bestFit # string, default: bestFit
    quality: 80 # default: 100

```

---

<div class="post-metadata">

### Author: ![gnagnu](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/gnagnu/32/572_2.png) [@gnagnu](https://discourse.getcockpit.com/u/gnagnu)
#### Post date: [September 2, 2020, 4:53pm UTC](https://discourse.getcockpit.com/t/new-addon-imageresize/903/2 "2020-09-02T16:53:42Z")

</div>

Hi @raffaelj  
I’d like to use this addon which is exactly what I need. Before I go ahead I wanted to know if you anticipate this to be compatible with the [Cloud Storage](https://github.com/agentejo/CloudStorage) addon?  
Thanks!  
Hang

---

<div class="post-metadata">

### Author: ![gnagnu](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/gnagnu/32/572_2.png) [@gnagnu](https://discourse.getcockpit.com/u/gnagnu)
#### Post date: [September 2, 2020, 6:24pm UTC](https://discourse.getcockpit.com/t/new-addon-imageresize/903/3 "2020-09-02T18:24:43Z")

</div>

Not sure if it is related but I get an error. Below is reponse of the /upload request.

Any idea?  
Thanks

Hang

```
<br />
<b>Warning</b>: imagesx() expects parameter 1 to be resource, null given in <b>/var/www/html/lib/vendor/claviska/simpleimage/src/claviska/SimpleImage.php</b> on line <b>457</b><br />
<br />
<b>Warning</b>: imagesy() expects parameter 1 to be resource, null given in <b>/var/www/html/lib/vendor/claviska/simpleimage/src/claviska/SimpleImage.php</b> on line <b>416</b><br />
<br />
<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /var/www/html/lib/vendor/claviska/simpleimage/src/claviska/SimpleImage.php:457) in <b>/var/www/html/bootstrap.php</b> on line <b>256</b><br />
<!doctype html>
<html lang="en" class="app-page-500">
<head>
    <meta charset="UTF-8">
    <title>Internal Server Error</title>
    <link rel="icon" href="/favicon.ico" type="image/x-icon">
    <link href="/assets/app/css/style.css?ver=0.11.0" type="text/css" rel="stylesheet"></head>
<body class="uk-height-viewport uk-flex uk-flex-middle">

    <div class="uk-container uk-container-center uk-text-center uk-animation-slide-bottom">

        <img src="/assets/app/media/icons/emoticon-sad.svg" width="150" height="150">

        <p class="uk-text-large uk-margin-large uk-text-bold">Uuuups, something went wrong.</p>

    </div>
</body>
</html>
```

---

<div class="post-metadata">

### Author: ![raffaelj](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/raffaelj/32/331_2.png) [@raffaelj](https://discourse.getcockpit.com/u/raffaelj)
#### Post date: [September 2, 2020, 6:32pm UTC](https://discourse.getcockpit.com/t/new-addon-imageresize/903/4 "2020-09-02T18:32:25Z")

</div>

@gnagnu I don’t think, that it is compatible with the cloud storage. I used functions like `mkdir` and `file_put_contents`, which should be replaced with something like `$app->filestorage->write()`.

I’m not experienced with external cdn, yet, so I can’t really test it.

---

<div class="post-metadata">

### Author: ![gnagnu](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/gnagnu/32/572_2.png) [@gnagnu](https://discourse.getcockpit.com/u/gnagnu)
#### Post date: [September 2, 2020, 9:45pm UTC](https://discourse.getcockpit.com/t/new-addon-imageresize/903/5 "2020-09-02T21:45:50Z")

</div>

Thanks @raffaelj I will try and update here if I find a solution.

---

<div class="post-metadata">

### Author: ![raffaelj](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/raffaelj/32/331_2.png) [@raffaelj](https://discourse.getcockpit.com/u/raffaelj)
#### Post date: [October 30, 2020, 1:57pm UTC](https://discourse.getcockpit.com/t/new-addon-imageresize/903/6 "2020-10-30T13:57:32Z")

</div>

@gnagnu The addon should now be compatible with the CloudStorage addon, but I wasn’t able to test it, yet.

Version 0.2.0 has new features and I rewrote a lot of the code.

> <https://github.com/raffaelj/cockpit_ImageResize/blob/master/CHANGELOG.md>

---

<div class="post-metadata">

### Author: ![Cryptospy](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/cryptospy/32/1169_2.png) [@Cryptospy](https://discourse.getcockpit.com/u/Cryptospy)
#### Post date: [September 15, 2022, 5:27pm UTC](https://discourse.getcockpit.com/t/new-addon-imageresize/903/7 "2022-09-15T17:27:22Z")

</div>

is this plugin compatible with Cockpit V2?

---

<div class="post-metadata">

### Author: ![raffaelj](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/raffaelj/32/331_2.png) [@raffaelj](https://discourse.getcockpit.com/u/raffaelj)
#### Post date: [September 15, 2022, 5:53pm UTC](https://discourse.getcockpit.com/t/new-addon-imageresize/903/8 "2022-09-15T17:53:01Z")

</div>

No. I guess, it’s time to update the README.md in a few repositories soon.

---

<div class="post-metadata">

### Author: ![Cryptospy](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/cryptospy/32/1169_2.png) [@Cryptospy](https://discourse.getcockpit.com/u/Cryptospy)
#### Post date: [September 15, 2022, 6:01pm UTC](https://discourse.getcockpit.com/t/new-addon-imageresize/903/9 "2022-09-15T18:01:15Z")

</div>

Do you have any plan of upgrading them, it was such an excellent use case for one of my project

---

<div class="post-metadata">

### Author: ![raffaelj](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/raffaelj/32/331_2.png) [@raffaelj](https://discourse.getcockpit.com/u/raffaelj)
#### Post date: [September 16, 2022, 8:51am UTC](https://discourse.getcockpit.com/t/new-addon-imageresize/903/10 "2022-09-16T08:51:47Z")

</div>

Not right now. I’m still testing Cockpit 2 and I didn’t read the code about current assets handling, yet.

What was your primary use case?

---

<div class="post-metadata">

### Author: ![Cryptospy](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/cryptospy/32/1169_2.png) [@Cryptospy](https://discourse.getcockpit.com/u/Cryptospy)
#### Post date: [September 19, 2022, 5:26am UTC](https://discourse.getcockpit.com/t/new-addon-imageresize/903/11 "2022-09-19T05:26:52Z")

</div>

tbh, my actual need was to regenerate images from the uploaded images and the size of the regenerated images being controllable via config file. better yet, if it could generate multiple set of images ( thumbnail, medium & large). Your plugin was the closest of what i needed. Something is better than nothing 😀

---

<div class="post-metadata">

### Author: ![raffaelj](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/raffaelj/32/331_2.png) [@raffaelj](https://discourse.getcockpit.com/u/raffaelj)
#### Post date: [September 19, 2022, 8:20am UTC](https://discourse.getcockpit.com/t/new-addon-imageresize/903/12 "2022-09-19T08:20:26Z")

</div>

> [@Cryptospy](#):
>
> better yet, if it could generate multiple set of images ( thumbnail, medium & large)

It can. That’s why I asked about your main use case.

---

<div class="post-metadata">

### Author: ![Cryptospy](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/cryptospy/32/1169_2.png) [@Cryptospy](https://discourse.getcockpit.com/u/Cryptospy)
#### Post date: [September 19, 2022, 9:07am UTC](https://discourse.getcockpit.com/t/new-addon-imageresize/903/13 "2022-09-19T09:07:25Z")

</div>

Awesome! plz do keep up your good work. looking forward to v2 compatible version ❤
