Example #1
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;
 }
Example #2
0
            			return strtr(base64_encode($input), '+/', '-_');
            		}*/
            function base64_url_decode($input)
            {
                return base64_decode(strtr(str_replace('=', '', $input), '-_,', '+/'));
            }
            $title = base64_url_decode($arr[1]);
            EnBacImage::thumbImageWithBackground(urldecode($arr[0]), 0, 0, 0, 1, $title, 1);
            exit;
        } else {
            //Xem ảnh max ko phun text
            $url_in = array("'thumb_max/([a-zA-Z0-9-_./]+)'");
            $url_out = array("\\1");
            $url_filter = preg_replace($url_in, $url_out, $url);
            $arr = explode(' ', $url_filter);
            if (count($arr) == 1) {
                //Kiem tra dieu kien view anh
                EnBacImage::thumbImageWithBackground(urldecode($arr[0]), 0, 0, 0, 1);
                exit;
            }
        }
    }
}
//header("Location: /enbac_logo.gif");
header("HTTP/1.0 404 Not Found");
echo "<h1>404 - Not Found!!!</h1>";
exit;
header("Location: /enbac_logo.gif");
//header("HTTP/1.0 404 Not Found");
//echo "<h1>404 - Not Found!<br />Return to <a href='http://enbac.com'>EnBac.com</a></h1>";
exit;
Example #3
0
<?php

error_reporting(E_ALL | E_NOTICE);
if (isset($_GET['xdebug']) && $_GET['xdebug'] > 0) {
    ini_set("profiler_output_dir", "./");
    ini_set("profiler_output_name", "cachegrind.out.%p");
    ini_set("xdebug.profiler_enable", 1);
}
require_once ROOT_PATH . "core/IMGlobal.php";
require_once ROOT_PATH . "core/config.php";
require_once ROOT_PATH . "core/ImageLib.php";
require_once ROOT_PATH . "core/EnBacImage.php";
global $thumb_size, $thumb_in_size, $thumb_w_size, $thumb_wl_size;
//Kích thước ảnh có chiều rộng x chiều dài
IMGlobal::$thumb_size = $thumb_size;
IMGlobal::$thumb_in_size = $thumb_in_size;
IMGlobal::$thumb_w_size = $thumb_w_size;
IMGlobal::$thumb_wl_size = $thumb_wl_size;
IMGlobal::$img_servers = $img_servers;
$host_arr = split("\\.", $_SERVER['HTTP_HOST']);
if (count($host_arr) == 3) {
    $s_img = $host_arr[0];
}
if (isset($s_img) && isset(IMGlobal::$img_servers[$s_img])) {
    EnBacImage::$path = IMGlobal::$img_servers[$s_img];
} else {
    EnBacImage::$path = current(IMGlobal::$img_servers);
}
unset($thumb_size, $thumb_w_size, $thumb_wl_size, $thumb_max_size, $img_servers, $host_arr, $s_img);