Jump to content

Resized images – purge originals?


yellowled
 Share

Recommended Posts

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

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

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.)

  • Like 11
Link to comment
Share on other sites

  • 7 years later...
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

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...