/**
  * Recreate images for a certain size
  */
 public function action_recreate()
 {
     ini_set('max_execution_time', 3600);
     // check if allowed
     if (!Acl::instance()->allowed($this->_controller, 'recreate')) {
         throw HTTP_Exception::factory(403, 'Not allowed to recreate images');
     }
     // get size
     $size = $this->request->param('id', FALSE);
     if ($size !== FALSE) {
         // get settings
         if ($settings = $this->_settings->get('sizes.' . $size, FALSE)) {
             // get all images
             $images = ORM::factory($this->_controller)->find_all();
             foreach ($images as $image) {
                 // check if the original exists
                 if (file_exists($this->_settings->get('path_files') . $image->file) && is_file($this->_settings->get('path_files') . $image->file)) {
                     // delete the requested size
                     FS::delete($this->_settings->get('path_images') . $size . DIRECTORY_SEPARATOR . $image->file);
                     // get existing sizes
                     $sizes = $image->sizes;
                     // unset this size
                     unset($sizes[$size]);
                     // recreate the wanted size
                     try {
                         $image->create_sizes($this->_settings->get('path_files') . $image->file, array($size => $settings), $this->_settings->get('path_images'));
                         // merge the original sizes and the newly created
                         $sizes = array_merge($sizes, $image->sizes);
                         // save these sizes
                         $image->sizes = $sizes;
                         $image->save();
                         //some feedback
                         echo 'recreated ' . $image->file . ' in size: ' . $size . '<br />';
                     } catch (Exception $e) {
                     }
                 }
             }
         }
     }
 }
 /**
  * delete files prior to item deletion
  */
 public function handle_file_after_delete($data)
 {
     $model = $data->deleted;
     // get file
     $file = $this->_settings->get('path_files') . $model->file;
     // delete it
     FS::delete($file);
 }