Example #1
0
 /**
  * Upload the logo
  *
  * @access private
  * @param $field
  * @return boolean
  */
 private function upload($field)
 {
     $this->load->library('upload');
     $this->load->helper('core');
     //verify whether the resize logo checkbox is checked
     $resize_logo = $this->input->post('resize');
     //upload the lgogo
     $this->upload->initialize(array('upload_path' => $this->logo_path, 'allowed_types' => 'gif|jpg|png|jpeg'));
     if ($this->upload->do_upload($field)) {
         //delete the original logo image
         $this->delete_logo('originals');
         //copy the uploade logo as the original logo
         $original_image = $this->logo_path . 'logo_originals' . $this->upload->data('file_ext');
         copy($this->upload->data('full_path'), $original_image);
         @unlink($this->upload->data('full_path'));
         //resize the original logo for each template
         $templates_map = directory_map(ROOTPATH . 'templates', 1);
         foreach ($templates_map as $template) {
             //ignore the base directory
             if ($template === 'base') {
                 continue;
             }
             //parse the template configuration file to get the logo width and height
             if (file_exists(ROOTPATH . 'templates/' . $template . '/template.xml')) {
                 $this->delete_logo($template);
                 //the resize logo checkbox is checked, get the logo with the defined width and height
                 if ($resize_logo == '1') {
                     $logo_width = $this->input->post('logo_width');
                     $logo_height = $this->input->post('logo_height');
                 } else {
                     $xml_info = simplexml_load_file(ROOTPATH . 'templates/' . $template . '/template.xml');
                     $logo_info = $xml_info->Logo[0]->attributes();
                     $logo_height = $logo_info['height'];
                     $logo_width = $logo_info['width'];
                 }
                 //resize the logo
                 $dest_image = $this->logo_path . 'logo_' . $template . $this->upload->data('file_ext');
                 if (!toc_gd_resize($original_image, $dest_image, (int) $logo_width, (int) $logo_height)) {
                     return FALSE;
                 }
             }
         }
         return TRUE;
     }
     return FALSE;
 }
Example #2
0
 /**
  * Resize the image
  *
  * @access public
  * @param $image
  * @param $group_id
  * @param $type
  * @return boolean
  */
 public function resize($image, $group_id, $type = 'products')
 {
     //ensure that the image group directory is existed
     if (!file_exists(ROOTPATH . 'images/' . $type . '/' . $this->_groups[$group_id]['code'])) {
         @mkdir(ROOTPATH . 'images/' . $type . '/' . $this->_groups[$group_id]['code'], 0777);
     }
     $original_image = ROOTPATH . 'images/' . $type . '/' . $this->_groups[1]['code'] . '/' . $image;
     $dest_image = ROOTPATH . 'images/' . $type . '/' . $this->_groups[$group_id]['code'] . '/' . $image;
     //verify that the product image is existing in the original image group and then resize it
     if (file_exists($original_image)) {
         toc_gd_resize($original_image, $dest_image, $this->_groups[$group_id]['size_width'], $this->_groups[$group_id]['size_height']);
         return TRUE;
     }
     return FALSE;
 }
Example #3
0
 /**
  * Resize product images
  *
  * @access private
  * @return void
  */
 public function resize_product_images()
 {
     $directories = directory_map('samples/images/products/originals', 1, TRUE);
     $images_groups = array('thumbnails' => array('width' => 140, 'height' => 140), 'product_info' => array('width' => 285, 'height' => 255), 'large' => array('width' => 480, 'height' => 360), 'mini' => array('width' => 57, 'height' => 57));
     foreach ($directories as $file) {
         if (strpos($file, '.jpg') !== FALSE || strpos($file, '.png') !== FALSE) {
             foreach ($images_groups as $name => $size) {
                 $original_image = 'samples/images/products/originals/' . $file;
                 $dest_image = '../images/products/' . $name . '/' . $file;
                 toc_gd_resize($original_image, $dest_image, $size['width'], $size['width']);
             }
         }
     }
 }