resize() public méthode

This is a wrapper function that chooses the proper resize function based on the protocol specified
public resize ( ) : boolean
Résultat boolean
Exemple #1
0
 public function processImage($template_id)
 {
     if (empty($template_id)) {
         return;
     }
     $this->CI->load->helper("upload");
     $path = UPLOAD_PATH . '../template/';
     $config['upload_dir'] = $path;
     $config['upload_dir'] = $config['upload_dir'];
     if (!is_dir($config['upload_dir'])) {
         //create the folder if it's not already exists
         mkdir($config['upload_dir'], 0755, TRUE);
     }
     $config['script_url'] = base_url() . $path;
     $config['upload_url'] = base_url() . $path;
     $upload_handler = new UploadHandler($config);
     header('Pragma: no-cache');
     header('Cache-Control: no-store, no-cache, must-revalidate');
     header('Content-Disposition: inline; filename="files.json"');
     header('X-Content-Type-Options: nosniff');
     header('Access-Control-Allow-Origin: *');
     header('Access-Control-Allow-Methods: OPTIONS, HEAD, GET, POST, PUT, DELETE');
     header('Access-Control-Allow-Headers: X-File-Name, X-File-Type, X-File-Size');
     switch ($_SERVER['REQUEST_METHOD']) {
         case 'OPTIONS':
             break;
         case 'HEAD':
         case 'GET':
             //$id_template= $template_id;
             $upload_dir = dirname($_SERVER['SCRIPT_FILENAME']) . $path;
             $url = base_url();
             $files = array();
             $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : "FRONT";
             //echo $type;
             if ($images = $this->CI->template_m->get_images($template_id, $type)) {
                 foreach ($images as $img) {
                     $returnpath = $path . $template_id . '_' . $img->id_image . $this->img_extension;
                     if (file_exists($returnpath)) {
                         $file = new stdClass();
                         $file->name = $template_id . '_' . $img->id_image . $this->img_extension;
                         $file->id_image = $img->id_image;
                         $file->url = $path . $template_id . '_' . $img->id_image . $this->img_extension;
                         $file->delete_url = site_url() . '/admin/template/img_upload' . '?id_image=' . rawurlencode($img->id_image) . '&&id_template=' . rawurlencode($template_id);
                         $file->delete_url .= '&&method=DELETE';
                         $file->deleteType = 'DELETE';
                         $file->url_default = site_url() . '/admin/template/set_default/' . $template_id . '/' . $img->id_image . '/' . $img->type;
                         $files[] = $file;
                     }
                 }
             }
             $obj = new stdClass();
             $obj->files = $files;
             ob_clean();
             print_r(json_encode($obj));
             ob_flush();
             break;
         case 'POST':
             if (isset($_REQUEST['method']) && $_REQUEST['method'] === 'DELETE') {
                 $upload_handler->delete();
             } else {
                 $id_template = $template_id;
                 $type = $this->CI->input->post('type') ? $this->CI->input->post('type') : "FRONT";
                 //parent::create($this->fields);
                 if (isset($_FILES['files'])) {
                     if ($timage = $this->CI->template_m->createimage($template_id, $type)) {
                         $new_file_path = $path . $id_template . "_" . $timage->id_image . $this->img_extension;
                         if (isset($_FILES['files']['tmp_name'][0])) {
                             $file_path = $_FILES['files']['tmp_name'][0];
                             if (file_exists($file_path)) {
                                 if ($file_path !== $new_file_path) {
                                     //	 @copy($file_path, $new_file_path);
                                     $config['image_library'] = 'gd2';
                                     $config['source_image'] = $file_path;
                                     $config['new_image'] = $new_file_path;
                                     $config['maintain_ratio'] = TRUE;
                                     $config['height'] = MAX_TEMPLATE_HEIGHT;
                                     $this->CI->load->library('image_lib');
                                     $resizer = new CI_Image_lib();
                                     $resizer->initialize($config);
                                     $resizer->resize();
                                 }
                             }
                         }
                     }
                     $files_return = array();
                     //     foreach ($images as $img) {
                     $file = new stdClass();
                     $file->name = $id_template . '_' . $timage->id_image . $this->img_extension;
                     $file->id_image = $timage->id_image;
                     $file->url = $path . $id_template . '_' . $timage->id_image . $this->img_extension;
                     $file->delete_url = $this->getFullUrl() . '/admin/template/img_upload' . '?id_image=' . rawurlencode($timage->id_image) . '&&id_template=' . rawurlencode($id_template);
                     $file->delete_url .= '&&method=DELETE';
                     $file->deleteType = 'DELETE';
                     $file->url_default = site_url() . '/admin/template/set_default/' . $id_template . '/' . $timage->id_image . '/' . $type;
                     $files_return[] = $file;
                     //  };
                     $object = new stdClass();
                     $object->files = $files_return;
                     ob_clean();
                     print_r(json_encode($object));
                     ob_flush();
                 }
             }
             break;
         case 'DELETE':
             if (!isset($_REQUEST['id_image'])) {
                 return;
             }
             if (!isset($_REQUEST['id_template'])) {
                 return;
             }
             $tid = $_REQUEST['id_template'];
             $image_id = $_REQUEST['id_image'];
             $this->CI->template_m->deleteimage($_REQUEST['id_image'], $_REQUEST['id_template']);
             $deltepath = $path . $tid . '_' . $image_id . $this->img_extension;
             //	echo $deltepath;die;
             if (file_exists($deltepath)) {
                 @unlink($deltepath);
             }
             ob_clean();
             ob_flush();
             //echo json_encode($this->tools->set_notification('N', 'notice', 'Delete successfull'));
             return;
             break;
         default:
             header('HTTP/1.1 405 Method Not Allowed');
     }
 }
Exemple #2
0
 private function importProcessImage($id, $imgPath)
 {
     $img = $this->template_m->createimage($id);
     //echo $imgPath;die;
     $returnpath = $this->tplateImageFolder . $id . '_' . $img->id_image . '.png';
     if (file_exists($imgPath)) {
         $config['image_library'] = 'gd2';
         $config['source_image'] = $imgPath;
         $config['new_image'] = $returnpath;
         $config['maintain_ratio'] = TRUE;
         $config['height'] = 600;
         $this->load->library('image_lib');
         $resizer = new CI_Image_lib();
         $resizer->initialize($config);
         $resizer->resize();
         return true;
     } else {
         return;
     }
 }
Exemple #3
0
 /**
  * 
  * @param string|integer $id (Primary Key)
  * @param string $name
  * @param string $folder (posts/images)
  * @return boolean
  */
 public static function upload($field, $id, $name, $folder, $config = array())
 {
     $CI =& get_instance();
     $ciConfig = $CI->config->item('utils');
     $config['upload_path'] = $path = $ciConfig['upload_dir'] . $folder . '/';
     $config['allowed_types'] = 'gif|jpg|png';
     $config['file_name'] = $fileName = self::getFileName($id, self::IMAGE_ORIGINAL, $name);
     $CI->load->library('upload');
     $CI->load->library('image_lib');
     $upload = new CI_Upload($config);
     if (!$upload->do_upload($field)) {
         return $upload->display_errors('', '');
     } else {
         $imageConfig = array('source_image' => $path . $fileName);
         foreach (array(self::IMAGE_LARGE, self::IMAGE_MEDIUM, self::IMAGE_SMALL) as $size) {
             $imageConfig['new_image'] = $path . self::getFileName($id, $size, $name);
             //                list($imageConfig['width'], $imageConfig['height']) = explode('x', $ciConfig['image'][strtolower($size)]);
             list($imageConfig['width']) = explode('x', $ciConfig['image'][strtolower($size)]);
             $image = new CI_Image_lib();
             $image->initialize($imageConfig);
             $image->resize();
             $image->clear();
         }
         $imageConfig['new_image'] = $path . self::getFileName($id, self::IMAGE_THUMB, $name);
         list($imageConfig['width'], $imageConfig['height']) = explode('x', $ciConfig['image'][strtolower(self::IMAGE_THUMB)]);
         $imageConfig['maintain_ratio'] = FALSE;
         $image = new CI_Image_lib();
         $image->initialize($imageConfig);
         $image->resize();
         $image->clear();
         return TRUE;
     }
 }
Exemple #4
0
/**
 * resize image
 * @author phplaw@gmail.com
 * @param array $opt array of config
 * @return mixed thumb_name or false when resize fail 
 */
function generate_thumb($opt = array())
{
    $config['image_library'] = 'gd2';
    $config['source_image'] = $opt['file_to_resize'];
    $config['thumb_marker'] = '';
    $config['new_image'] = $opt['thumb_dir'];
    $config['create_thumb'] = TRUE;
    $config['master_dim'] = 'width';
    $config['width'] = $opt['width'];
    $config['height'] = $opt['height'];
    $CI_Image_lib = new CI_Image_lib($config);
    if ($CI_Image_lib->resize()) {
        return $CI_Image_lib->dest_image;
    }
    return false;
}