New Addon: ImageResize

I wrote an addon to resize uploaded images automatically. It might share some behavior with 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

Related discusson

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:

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

extra keys:

"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.

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
2 Likes

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 addon?
Thanks!
Hang

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>

@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.

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

@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.

is this plugin compatible with Cockpit V2?

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

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

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?

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 :grinning:

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

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

1 Like