Example #1
0
             break;
         case "image/pjpeg":
         case "image/jpeg":
         case "image/jpg":
             $createdImage = imagejpeg($newImage, $tempName, 99);
             break;
         case "image/png":
         case "image/x-png":
             $createdImage = imagepng($newImage, $tempName);
             break;
     }
     if ($createdImage) {
         if (ImageLib::ftp_check_dir('up_new', true)) {
             if (ImageLib::ftp_image_put_file($cropName, $tempName)) {
                 unlink($tempName);
                 ImageLib::ftp_image_delete_file($imageName);
                 $return = 'true';
             } else {
                 $return = 'false,Copy file failed, permission denied';
             }
         } else {
             $return = 'false,Destination folder not found';
         }
     } else {
         $return = 'false,Refine image failed';
     }
 } else {
     switch ($imageType) {
         case "image/gif":
             $createdImage = imagegif($newImage, $cropName);
             break;
Example #2
0
 static function thumbImageNoBG($imageSource, $width = 0, $height = 0)
 {
     if ($width <= 0 && $height <= 0) {
         return '';
     }
     if ($imageSource != '') {
         if (!file_exists(EnBacImage::$path . UP_FOLDER . "/" . $imageSource)) {
             $imageSource = DEFAULT_IMAGE;
         }
     } else {
         $imageSource = DEFAULT_IMAGE;
     }
     $file_ext = self::getExtension($imageSource);
     if ($height && $width) {
         $thumbDir = "thumb_in/{$width}_{$height}/";
     } else {
         $thumbDir = '';
     }
     if ($thumbDir && $imageSource == DEFAULT_IMAGE) {
         //Nếu ở chế độ view ảnh thumb mà k thấy ảnh gốc!
         header("HTTP/1.0 404 Not Found");
         echo "<h1>404 - Not Found!</h1>";
         exit;
     }
     $get_direct_img = false;
     if (CACHE_ON) {
         $tempCacheDir = '';
         $tempCacheFile = '';
         if ($thumbDir) {
             $cacheDir = $thumbDir . dirname($imageSource) . '/';
             $tempCacheDir = IMG_TEMP_DIR . $cacheDir;
             $tempCacheFile = $tempCacheDir . basename($imageSource);
             $cache_file = $thumbDir . $imageSource;
             $checkCacheFile = CHECK_PATH . $cache_file;
         } else {
             if ($imageSource != DEFAULT_IMAGE) {
                 $cacheDir = dirname($imageSource);
                 if (strpos($imageSource, 'category/') === 0) {
                     $cacheDir = 'category';
                 }
                 $tempCacheDir = $cacheDir;
                 if ($cacheDir != '' && (is_dir($cacheDir) || $cacheDir == 'category') && $cacheDir != '.') {
                     $cacheDir = IMG_CACHE_PATH . $cacheDir . '/';
                     $tempCacheDir = IMG_TEMP_DIR . $cacheDir . '/';
                 } else {
                     $cacheDir = IMG_CACHE_PATH . 'enbac/';
                     $tempCacheDir = IMG_TEMP_DIR . 'enbac/';
                 }
             } else {
                 $get_direct_img = true;
                 $cacheDir = IMG_CACHE_PATH . 'blank/';
                 $tempCacheDir = IMG_TEMP_DIR . 'blank/';
             }
             $QUERY_STRING = $_SERVER['QUERY_STRING'];
             if (isset($_GET['delimg'])) {
                 $QUERY_STRING = str_replace(array('delimg=' . $_GET['delimg'] . '&', '&delimg=' . $_GET['delimg'], 'delimg=' . $_GET['delimg']), '', $QUERY_STRING);
             }
             $cache_file = md5(str_replace("&amp;", "&", $QUERY_STRING)) . $file_ext;
             $tempCacheFile = $tempCacheDir . $cache_file;
             $cache_file = $cacheDir . $cache_file;
             $checkCacheFile = CHECK_PATH . $cache_file;
         }
         $del_cache = (int) (isset($_GET['delimg']) && (int) $_GET['delimg'] == 1);
         //Lấy cache ra:
         if (@file_exists($checkCacheFile) && !$del_cache) {
             @header("Location: " . IMG_CACHE_URL . $cache_file);
             exit;
         }
     }
     $thumbImage = new EnBacImage();
     $thumbImage->loadfile(UP_FOLDER . "/" . $imageSource, $get_direct_img);
     if ($thumbImage->width > $width || $thumbImage->height > $height) {
         if ($thumbImage->width / $thumbImage->height <= $width / $height) {
             $thumbImage->resizetoheight($height);
         } else {
             $thumbImage->resizetowidth($width);
         }
     }
     if (CACHE_ON && $cache_file) {
         if (FTP_CACHE && $tempCacheFile && ImageLib::CheckDir($tempCacheDir) && ImageLib::ftp_check_dir($cacheDir)) {
             //Che do ghi cache qua ftp
             $thumbImage->savefile($tempCacheFile);
             if (@file_exists($tempCacheFile)) {
                 //upload file via ftp
                 ImageLib::ftp_image_delete_file($cache_file);
                 ImageLib::ftp_image_put_file($cache_file, $tempCacheFile);
                 @unlink($tempCacheFile);
                 ImageLib::ftp_image_close();
             }
         } elseif (ImageLib::CheckDir($cacheDir)) {
             $thumbImage->savefile($cache_file);
         }
         if (!FIRST_SHOW_IMAGE && @file_exists($checkCacheFile)) {
             @header("Location: " . IMG_CACHE_URL . $cache_file);
             imagedestroy($thumbImage->ImageStream);
             exit;
         }
     }
     //show img
     if (SET_HEADER) {
         //standard method #
         header('HTTP/1.0 200 OK');
         //HTTP/1.1 200 OK
         //CGI method #
         header('Status: 200 OK');
         header("Expires: ");
         header("Last-Modified: ");
         header('Cache-Control: public,max-age=2592000');
         //Adjust maxage appropriately
         header('Pragma: public');
         //header("Cache-Control: public, must-revalidate");header("Pragma: hack");
     }
     if (stripos($_SERVER['HTTP_USER_AGENT'], "msie") === false) {
         header('Content-type: ' . $thumbImage->mimetype);
     }
     if (SET_HEADER) {
         header('Content-Disposition: inline; filename=' . basename($imageSource, $file_ext));
     }
     $thumbImage->showImage($quality);
     imagedestroy($thumbImage->ImageStream);
     exit;
 }