Advertisement
Guest User

Untitled

a guest
Jul 6th, 2011
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.20 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Upload Helper
  5.  *
  6.  * @package helpers
  7.  * @date        04:39 ‎07/‎07/‎2011
  8.  */
  9. class Helper_Upload {
  10.  
  11.     /**
  12.       * Resize the image and create a thumb.
  13.       *
  14.       * @param  array   $file
  15.       * @return void
  16.      */
  17.     public static function save_image($file)
  18.     {
  19.         // Get default config for resize
  20.         \Config::load('upload','upload');
  21.        
  22.         // Validate the current file
  23.         if ($file['error'] == \Upload::UPLOAD_ERR_OK)
  24.         {
  25.             $file_path = $file['saved_to'].DS.$file['saved_as'];
  26.  
  27.             // Resize the image
  28.             // Clear the last image obj by calling factory first
  29.             \Image::factory(null, $file_path)
  30.                 ->resize(\Config::get('upload.resize_w'), \Config::get('upload.resize_h'))
  31.                 ->save($file_path);
  32.            
  33.             // Create image thumb
  34.             \Image::load($file_path)
  35.                 ->resize(\Config::get('upload.thumb_w'), \Config::get('upload.thumb_h'))
  36.                 ->save_pa('', '_thumb'); // You're genius!
  37.         }
  38.     }
  39.  
  40.     /**
  41.      * Get image thumb file.
  42.      *
  43.      * @access  public
  44.      * @param   string  $image
  45.      * @return  string
  46.      */
  47.     public static function thumb_file($image)
  48.     {
  49.         $ext = $image['extension'];
  50.        
  51.         return substr($image['saved_to'], 0, -(strlen($ext) + 1)).'_thumb.'.$ext;
  52.     }
  53.    
  54. }
  55.  
  56. /* End of file upload.php */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement