MuchDev Posted October 4, 2015 Share Posted October 4, 2015 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 More sharing options...
LostKobrakai Posted October 4, 2015 Share Posted October 4, 2015 If I use this how would I go about getting the file path from the event? $resizer = $event->object; $filename = $resizer->filename; 1 Link to comment Share on other sites More sharing options...
MuchDev Posted October 4, 2015 Author Share Posted October 4, 2015 Fantastic! Thanks man, that makes sense. I'll test it out and post my solution . Link to comment Share on other sites More sharing options...
MuchDev Posted October 4, 2015 Author Share Posted October 4, 2015 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now