yellowled Posted November 30, 2012 Share Posted November 30, 2012 I usually use $item->size() wherever possible to make sure clients don't put huge images in pages. However, even so, the uploaded original image remains in /site/assets/files/, potentially taking up a lot of webspace. And I guess we all have had clients who just couldn't bet bothered to resize their digital photos before uploading them. Once proper thumbnails are generated in PW, is it safe to delete the original file? And if so, could this maybe be automated in some way? (I don't dare dreaming of a module for this …) Link to comment Share on other sites More sharing options...
Soma Posted November 30, 2012 Share Posted November 30, 2012 Why not just limit width and or height in the image field settings? Link to comment Share on other sites More sharing options...
yellowled Posted November 30, 2012 Author Share Posted November 30, 2012 Well, obviously. But I didn't think of that when I built one particular site, which unfortunately happens to have quite a lot of images. And most of them are being uploaded directly from digital cameras … Technically, it probably doesn't make a lot of sense to purge the originals. Let's say I changed the thumbnail sizes in the template. In that case, resizing the thumbnails would fail because the originals was no longer available. Link to comment Share on other sites More sharing options...
Soma Posted November 30, 2012 Share Posted November 30, 2012 Well deleting the original will leave you with a problem as you already know It would be relatively easy to script a batch resize all original images and run that once over all page that has images. Use the ImageSizer class. Working example: $pa = $pages->find("template=basic-page,images.count>0"); foreach($pa as $p){ foreach($p->images as $i){ $ImageSizer = new ImageSizer($i->filename); $ImageSizer->resize(120,0); } } It will resize all the original images to 120x*. And you're done. (This particular example show how cool the on-page images are.) 11 Link to comment Share on other sites More sharing options...
yellowled Posted November 30, 2012 Author Share Posted November 30, 2012 Thanks, soma. (This is so great. One could probably even expand this to check the images for size before resizing them. No, don't tell me how, I want to find out myself.) Link to comment Share on other sites More sharing options...
benbyf Posted February 20, 2020 Share Posted February 20, 2020 On 11/30/2012 at 11:22 AM, Soma said: Working example: $pa = $pages->find("template=basic-page,images.count>0"); foreach($pa as $p){ foreach($p->images as $i){ $ImageSizer = new ImageSizer($i->filename); $ImageSizer->resize(120,0); } } will this need a $p->save to make it work? 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