Jump to content

pre process template image sizes


benbyf
 Share

Recommended Posts

Hello!

I often have to change image sizes in templates using the ->width() or size functions and on a image heavy site this a cause timeout errors or massie lag before all the images are resized when changing to the new template.

I was wondering if there was a good way of creating these images without having to hit each page on the site for the template to be called and images updated? Basically to avoid the errors?

Thanks

Link to comment
Share on other sites

Or use

http://modules.processwire.com/modules/fieldtype-crop-image/

or

https://github.com/horst-n/CroppableImage

to generate the pre-generate the needed thumbnail sizes and call them directly int the template like

// get the first image instance of crop setting 'portrait'
$image = $page->images->first()->getCrop('portrait');

regards mr-fan

  • Like 2
Link to comment
Share on other sites

Hello,

in PW I really like possibility to dynamic resize images in template, but also maybe - one day - there can be and option for multiple thumbnails creation over upload process.

Also in some cases cron jobs (background server scheduled tasks) are solution.

regards,

Sasa

  • Like 1
Link to comment
Share on other sites

Think the crop images module is probably the best option here as it creates the image straight away but slightly fustrating if you dont want to install any new modules etc. if you changes the image field to a crop field would it create the crop images for the site or only when you edit that page?

not sure how i would set up a cron job - might be time to try

Link to comment
Share on other sites

should work with a little API snippet...to save all pages and create the thumbs on save...didn't mentioned this before since i've this module in my setup from the start building a site...

//not tested!!
$mypages = $pages->find(template=mytemplatewithimages);
foreach($mypages as $p) {
    $p->save();
}
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...