Jay D Posted June 10, 2023 Share Posted June 10, 2023 Hi all! I want to check my sanity on this one, I want to create multiple versions of an image when uploading to PW Admin, think Hero and Thumbnail. I am not finding any recent modules, so I decided to write one. Now I am having an issue where I am not able to access Image method. Does anyone have an example of how to manipulate images once it is processed? And is there a good document on how to debug the API calls? I want to avoid having the images processed every time a page is loaded, or when the cache is cleared. Thanks, Jay Link to comment Share on other sites More sharing options...
cwsoft Posted June 10, 2023 Share Posted June 10, 2023 @Jay DYou could try to hook into the page save event via the ready.php file to create/update images of a given page/template. Not dealed yet much with image manipulation myself. But doesn‘t the default image field allow to manipulate the image already. Coding wise you could use the image API https://processwire.com/api/ref/pageimage/size/. 1 Link to comment Share on other sites More sharing options...
zoeck Posted June 10, 2023 Share Posted June 10, 2023 You can have a Look at the Croppable Image 3 Module https://processwire.com/modules/croppable-image3/ 2 Link to comment Share on other sites More sharing options...
flydev Posted June 11, 2023 Share Posted June 11, 2023 You can also generate desired image variations when you upload an image in the field: /** * // in ready.php * Image variations * Generate image variations on upload * Pageimage api ref: https://processwire.com/api/ref/pageimage/ */ $this->wire()->addHookAfter('InputfieldImage::fileAdded', function ($event) { $inputfield = $event->object; $image = $event->argumentsByName("pagefile"); // `image` field on `document` template if ($inputfield->hasField == 'image' && $inputfield->hasPage && $inputfield->hasPage->template->name == 'document') { // some custom options $defaultOptions = array( 'upscaling' => false, 'cropping' => false, 'quality' => 90, ); // generate image variations // See wire/config.php for $config->sizeName: https://github.com/processwire/processwire/blob/master/wire/config.php#L726-L789 $image->size('landscape'); // 16/9 defined size `landscape` from $config->sizeName $image->size(200, 250); // 4/3 thumbnails } }); For debugging => https://processwire.com/modules/tracy-debugger/ 3 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