zeloras

Untitled

May 17th, 2014
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.12 KB | None | 0 0
  1. if ( ! function_exists('image_resize'))
  2. {
  3.     function image_resize($image, $type = 'catalog')
  4.     {
  5.         $data_type = array(
  6.             'catalog' => 'image_catalog',
  7.             'brand' => 'image_brand',
  8.             'category' => 'image_category',
  9.             'main' => 'image_main',
  10.             'gallery' => 'image_gallery',
  11.         );
  12.         $thumb_file_extype = "_".$type;
  13.         $images = '';
  14.         $ci =& get_instance();
  15.         $ci->load->library('image_lib');
  16.  
  17.         $ci->db->select('settings');
  18.         $settings_query = $ci->db->get("myshop_settings")->result();
  19.         $settings = unserialize($settings_query[0]->settings);
  20.        
  21.         $root_path = $_SERVER['DOCUMENT_ROOT'];
  22.         if (is_array($image) && sizeof($image) > 0)
  23.         {
  24.             foreach ($image as $key => $im)
  25.             {
  26.                 $file_name = basename($im);
  27.                 $file_path_exp = explode($file_name, $im);
  28.                 $file_path = $file_path_exp[0];
  29.                 $file_path_thumb = $file_path."_thumbs";
  30.                 if (!file_exists($root_path.$file_path_thumb))
  31.                     mkdir($root_path.$file_path_thumb);
  32.                
  33.                 $file_exp = explode('.', $file_name);
  34.                 $file_extension = $file_exp[sizeof($file_exp) - 1];
  35.                 array_pop($file_exp);
  36.                 $to_file_thumb = $file_path_thumb."/".implode('.',$file_exp).$thumb_file_extype.".".$file_extension;
  37.                 $thumb_file = $file_path_thumb."/".implode('.',$file_exp).$thumb_file_extype."_thumb.".$file_extension;
  38.                 if (file_exists($root_path.$im))
  39.                 {
  40.                     if (!file_exists($root_path.$thumb_file) && $settings[$data_type[$type]]['resize_on'] == 1)
  41.                     {
  42.                         $config['image_library'] = 'gd2';
  43.                         $config['source_image'] = $root_path.$im;
  44.                         $config['create_thumb'] = TRUE;
  45.                         $config['new_image'] = $root_path.$to_file_thumb;
  46.                         $config['maintain_ratio'] = ($settings[$data_type[$type]]['maintain'] == 1) ? TRUE : FALSE;
  47.                         $config['width'] = $settings[$data_type[$type]]['width'];
  48.                         $config['height'] = $settings[$data_type[$type]]['height'];
  49.                         $config['quality'] = $settings[$data_type[$type]]['quality'];
  50.                         $ci->image_lib->initialize($config);
  51.                         $ci->image_lib->resize();
  52.                     }
  53.  
  54.                     if (!$settings[$data_type[$type]]['resize_on'])
  55.                         $thumb_file = $im;
  56.                    
  57.                     $images[$key] = array(
  58.                         'image' => $im,
  59.                         'thumb' => $thumb_file,
  60.                     );
  61.                 }
  62.             }
  63.         }
  64.         else
  65.         {
  66.             if (file_exists($root_path.$image) && strlen($image) > 4)
  67.             {
  68.                 $file_name = basename($image);
  69.                 $file_path_exp = explode($file_name, $image);
  70.                 $file_path = $file_path_exp[0];
  71.                 $file_path_thumb = $file_path."_thumbs";
  72.                 //var_dump($file_path_thumb);
  73.                 if (!file_exists($root_path.$file_path_thumb))
  74.                     mkdir($root_path.$file_path_thumb);
  75.  
  76.                 $file_exp = explode('.', $file_name);
  77.                 $file_extension = $file_exp[sizeof($file_exp) - 1];
  78.                 array_pop($file_exp);
  79.                 $to_file_thumb = $file_path_thumb."/".implode('.',$file_exp).$thumb_file_extype.".".$file_extension;
  80.                 $thumb_file = $file_path_thumb."/".implode('.',$file_exp).$thumb_file_extype."_thumb.".$file_extension;
  81.                
  82.                 if (!file_exists($root_path.$thumb_file) && $settings[$data_type[$type]]['resize_on'] == 1)
  83.                 {
  84.                     $config['image_library'] = 'gd2';
  85.                     $config['source_image'] = $root_path.$image;
  86.                     $config['create_thumb'] = TRUE;
  87.                     $config['new_image'] = $root_path.$to_file_thumb;
  88.                     $config['maintain_ratio'] = ($settings[$data_type[$type]]['maintain'] == 1) ? TRUE : FALSE;
  89.                     $config['width'] = $settings[$data_type[$type]]['width'];
  90.                     $config['height'] = $settings[$data_type[$type]]['height'];
  91.                     $config['quality'] = $settings[$data_type[$type]]['quality'];
  92.                     $ci->image_lib->initialize($config);
  93.                     $ci->image_lib->resize();
  94.                 }
  95.                
  96.                 if (!$settings[$data_type[$type]]['resize_on'])
  97.                    $thumb_file = $image;
  98.                
  99.                     $images[0] = array(
  100.                         'image' => $image,
  101.                         'thumb' => $thumb_file,
  102.                     );
  103.             }
  104.             else
  105.             {
  106.                     $images[0] = array(
  107.                         'image' => $image,
  108.                         'thumb' => $image,
  109.                     );
  110.             }
  111.         }
  112.         return $images;
  113.     }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment