Jump to content

Use resized image as the default image


blad
 Share

Recommended Posts

My client is saturating the server capacity with tons of images, the images are resized but the original still on the server. How can I use the resized images and delete the original?

I use the following module created by @soma:

The post here

<?php
class ImageCreateThumbs extends WireData implements Module {

    public static function getModuleInfo() {
        return array(
            'title' => 'ImageCreateThumbs',
            'version' => 100,
            'summary' => '',
            'href' => '',
            'singular' => true,
            'autoload' => true
            );
    }

    public function init() {
        $this->addHookAfter('InputfieldFile::fileAdded', $this, 'sizeImage');
    }

    public function sizeImage($event) {
        $inputfield = $event->object;
        if($inputfield->name != 'prop_imagen') return; // we assume images field
        $image = $event->argumentsByName("pagefile");
        $image->size(120,120);
        $image->size(1000,0);
            }
            
}
Thank you in advance.
Link to comment
Share on other sites

@blad: you simply can set maxwidth and maxheight for the imagefield(s). Look at input Tab in the admin. I'm on mobile.

There is no module needed, Setting both fields to 800 for example resizes the original Image with the largest side to 800px.

Edit: wow, it seems it tooks me 4 minutes to post that on a much to small smartphone. @blad: nice you have found it.

  • Like 2
Link to comment
Share on other sites

@blad: you simply can set maxwidth and maxheight for the imagefield(s). Look at input Tab in the admin. I'm on mobile.

There is no module needed, Setting both fields to 800 for example resizes the original Image with the largest side to 800px.

Edit: wow, it seems it tooks me 4 minutes to post that on a much to small smartphone. @blad: nice you have found it.

I don't know what I'm thinking! My head doesn't feel too strong today. Thanks @horst.

The next post will be "10 Most stupid questions by blad"

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...