Ejemplo n.º 1
0
 public static function create($pathOriginal, $width, $height, $option = self::NORMAL)
 {
     $original = new ThumbImage($pathOriginal);
     $thumbSize = array('width' => $width, 'height' => $height);
     $thumbPath = self::getPath($pathOriginal, $thumbSize, $option);
     $forceSize = $option != self::NORMAL and $option != self::HEIGHT;
     if (file_exists($thumbPath)) {
         return $thumbPath;
     }
     if ($original->correctSize($thumbSize)) {
         return $pathOriginal;
     }
     if ($original->isToSmall($thumbSize) && !$forceSize) {
         return $pathOriginal;
     }
     $image = $original->scale($thumbSize, $option);
     self::save($image, $thumbPath);
     return $thumbPath;
 }
Ejemplo n.º 2
0
 function upload()
 {
     $json['error'] = 'not_uploaded';
     $json['image_url'] = '';
     if (User::is_login()) {
         $upload_path = DIR_CACHE . 'ad_images/';
         AZLib::CheckDir($upload_path);
         $uploadFile = $_FILES["fast_upload"];
         if (isset($uploadFile) && $uploadFile['name']) {
             $file_name = TIME_NOW . strtolower($uploadFile['name']);
             $sourceName = $uploadFile['tmp_name'];
             $file_ext = AZLib::getExtension($file_name);
             if (in_array($file_ext, array('.jpg', '.jpeg', '.gif', '.png'))) {
                 if (!$uploadFile['error']) {
                     $newFile = $upload_path . $file_name;
                     //$width = 300;
                     //$height = 255;
                     //$this->genImageFromSource($sourceName,$upload_path.$file_name,$width);
                     include_once ROOT_PATH . 'core/ThumbImage.php';
                     $ThumbImage = new ThumbImage();
                     $ThumbImage->ThumbImageWithBackground($sourceName, $file_name, 300);
                     // Tạo cache đã resize cho ảnh quảng cáo
                     // Upload lên server ảnh, fix lỗi không tìm thấy file cache với server load balancing
                     $img_path = 'upnew/cpc/';
                     AZLib::ftp_image_put_file($img_path . $file_name, $newFile, IMAGE_SERVER_NO);
                     $img_url = $img_path . $file_name;
                     $json['image_domain'] = 'http://' . CGlobal::$img_server[IMAGE_SERVER_NO];
                     $json['image_url'] = $img_url;
                     $json['error'] = 'success';
                 } elseif ($uploadFile['error'] == 1) {
                     $json['error'] = 'over_max_size';
                 }
             } else {
                 $json['error'] = 'ext_invalid';
                 //Sai định dạng file
             }
         } else {
             $json['error'] = 'destination_not_exist';
         }
     } else {
         $json['error'] = 'not_login';
     }
     echo json_encode($json);
     exit;
 }