public function actionIndex($url, $width)
 {
     $imcache = new ImageCache();
     header('Content-type: image/jpeg');
     if ($imcache->imageInCache($url, $width)) {
         $imagelink = $imcache->getImageLink($url, $width);
         readfile($imagelink);
     } else {
         readfile($url);
         $imcache->getImageLink($url, $width);
     }
 }
Example #2
0
 /**
  * A smart thumbnailing function. Generates thumbnail images without
  * distorting the output of the final image.
  * 
  * @param string $file
  * @param string $width
  * @param string $height
  * @param string $head
  * @return string
  */
 public static function thumbnail($file, $width, $height, $head = false)
 {
     if (!is_file($file)) {
         return;
     }
     $uuid = md5($file);
     $src = SOFTWARE_HOME . "app/temp/{$uuid}.thumb.{$width}.{$height}.jpeg";
     if (!is_file($src) || filectime($file) > filectime($src)) {
         $im = imagecreatefromjpeg($file);
         $i_width = imagesx($im);
         $i_height = imagesy($im);
         imagedestroy($im);
         $tempImage = uniqid() . ".jpeg";
         if ($width > $height) {
             ImageCache::resize_image($file, SOFTWARE_HOME . "app/temp/{$tempImage}", $width, 0);
             ImageCache::crop_image(SOFTWARE_HOME . "app/temp/{$tempImage}", $src, $width, $height, $head);
         } else {
             if ($height > $width) {
                 ImageCache::resize_image($file, SOFTWARE_HOME . "app/temp/{$tempImage}", $height, 0);
                 ImageCache::crop_image(SOFTWARE_HOME . "app/temp/{$tempImage}", $src, $width, $height, $head);
             } else {
                 if ($i_width > $i_height) {
                     ImageCache::resize_image($file, SOFTWARE_HOME . "app/temp/{$tempImage}", 0, $height);
                 } else {
                     ImageCache::resize_image($file, SOFTWARE_HOME . "app/temp/{$tempImage}", $width, 0);
                 }
                 ImageCache::crop_image(SOFTWARE_HOME . "app/temp/{$tempImage}", $src, $width, $height, $head);
             }
         }
         unlink(SOFTWARE_HOME . "app/temp/{$tempImage}");
     }
     return $src;
 }
Example #3
0
require_once "core/include/base/system/autoload.function.php";
SystemConfig::load_module_config();
if ($_GET['session_id'] and $_GET['file_id']) {
    $transaction = new Transaction();
    try {
        $system_handler = new SystemHandler(false);
    } catch (Exception $e) {
        die("Exception");
    }
    Security::protect_session();
    $session = new Session($_GET['session_id']);
    $user = new User($session->get_user_id());
    $session_valid_array = $session->is_valid();
    if ($session_valid_array[0] === true) {
        try {
            $image_cache = new ImageCache($_GET['file_id']);
        } catch (Exception $e) {
            die("Exception");
        }
        if ($_GET['max_width']) {
            $image_cache->set_max_width($_GET['max_width']);
        }
        if ($_GET['max_height']) {
            $image_cache->set_max_height($_GET['max_height']);
        }
        if ($_GET['width']) {
            $file_path = constant("BASE_DIR") . "/filesystem/temp/" . $image_cache->get_image($_GET['width']);
        } elseif ($_GET['height']) {
            $file_path = constant("BASE_DIR") . "/filesystem/temp/" . $image_cache->get_image(null, $_GET['height']);
        } else {
            $file_path = constant("BASE_DIR") . "/filesystem/temp/" . $image_cache->get_image();
Example #4
0
<head>
	<meta charset="UTF-8">
	<title>Image Cache Test</title>
	<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
	<style>
		body {
			font-family: 'Open Sans', Helvetica, Arial, sans-serif;
		}
		img {
			max-width: 100%;
		}
	</style>
</head>
<body>
	<?php 
$imagecache = new ImageCache();
$imagecache->cached_image_directory = dirname(__FILE__) . '/images/cached';
$cached_src_one = $imagecache->cache('images/unsplash1.jpeg');
echo '<p>Original file size: ' . filesize($imagecache->image_src) . ' bytes</p>';
echo '<p>PHPImageCach-ified file size: ' . filesize($imagecache->cached_filename) . ' bytes</p>';
echo '<p>Total image size reduction: ' . (filesize($imagecache->image_src) - filesize($imagecache->cached_filename)) / filesize($imagecache->image_src) * 100 . '%</p>';
?>
	<img src="<?php 
echo $cached_src_one;
?>
" alt="">
	<hr>
	<?php 
$cached_src_two = $imagecache->cache('images/unsplash2.jpeg');
echo '<p>Original file size: ' . filesize($imagecache->image_src) . ' bytes</p>';
echo '<p>PHPImageCach-ified file size: ' . filesize($imagecache->cached_filename) . ' bytes</p>';
 public function action_index()
 {
     $this->auto_render = FALSE;
     $image = new ImageCache();
     $image->output_file();
 }
 /**
  * @author nielse63
  * @depends testCanFindFile
  */
 public function testCanRunImageCache()
 {
     $imagecache = new ImageCache();
     $this->assertTrue($imagecache->can_run_image_cache());
 }