Jump to content

Hook to Imagesizer::resize


MuchDev
 Share

Recommended Posts

Hey quick question I hope. I am trying to find the right method to go about getting the filepath of all images when they are saved or resized in a hook. 

If I use this how would I go about getting the file path from the event?

$this->addHookAfter('ImageSizer::resize', $this, 'compressImage');

I will then be passing this off to a script which automates the usage of pngcrush and jpegtran. 

ImageCrusher::batch($path, true ); // recursive
Link to comment
Share on other sites

Works like a charm :) 
Well here is some code, the bulk of it soma wrote which handles creating extra images so that on batch uploads there is less of an inital page load. After that it just executes a script that wraps the two programs.

Here is the script: LINK 

<?php
include 'ImageCrusher.php';
class ImageCreateThumbs extends WireData implements Module {

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

    public function init() {
        $this->addHookAfter('InputfieldFile::fileAdded', $this, 'sizeCrushImage');
		$this->addHookAfter('ImageSizer::resize', $this, 'crushImage');
    }

    public function sizeCrushImage($event) {
        $inputfield = $event->object;
        if($inputfield->name != 'artwork_img') return; //image field here
        $image = $event->argumentsByName("pagefile");
		$image->width(900);	
		//$image->width(1116);		
		$image->width(365);	
		$image->width(255);	
		
		$path = "/home/username/public_html".dirname($image->url);
		ImageCrusher::batch($path, true ); // recursive
    }
	
    public function crushImage($event) {	
		$path = $event->object->filename;
		$crusher = new ImageCrusher($path);
		$crusher->crush();
    }	
}
?>
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...