This is the GD Implementation of the PHP Thumb library.
Example #1
0
 function thumb($request)
 {
     header("Content-Type: image/png");
     header("Cache-Control: private, max-age=10800, pre-check=10800");
     header("Pragma: private");
     header("Expires: " . date(DATE_RFC822, strtotime(" 1 day")));
     $imageSizes = array('thumb' => '100x75', 'square' => '150x150', 'small' => '640x480', 'medium' => '800x600', 'large' => '1024x768', 'original' => '1024x768');
     ///media/(.*?)/(thumb|square|small|medium|large)/
     //if (preg_match("/ell/", "Hello World!", $matches)) {
     $urlArr = explode('/', $_SERVER["REQUEST_URI"]);
     $imageSize = $urlArr[count($urlArr) - 2];
     if (array_key_exists($imageSize, $imageSizes)) {
         unset($urlArr[count($urlArr) - 2]);
     } else {
         $imageSize = 'original';
     }
     $url = preg_replace('/(.*?)media\\//i', '/media/', implode('/', $urlArr));
     $originalFile = urldecode(SITE_PATH . $url);
     $cacheFolder = sprintf('%s/cache/images/%s', SITE_PATH, $imageSize);
     $cacheFile = sprintf('%s/%s', $cacheFolder, implode('-', $urlArr));
     $fileInfo = pathinfo($originalFile);
     if (!is_dir($cacheFolder)) {
         @mkdir($cacheFolder, 0755, true);
     }
     if (@is_file(sprintf('%s/media/admn/img/icons/256/%s.png', APPLICATION_PATH, $fileInfo['extension']))) {
         readfile(sprintf('%s/media/admn/img/icons/256/%s.png', APPLICATION_PATH, $fileInfo['extension']));
     } else {
         if (!is_file($cacheFile)) {
             if (is_file($originalFile)) {
                 try {
                     $options = array('jpegQuality' => 80);
                     $thumb = new PhpThumb($originalFile);
                     $thumb->setOptions($options);
                     //$newDimensions = $thumb->getCurrentDimensions();
                     //if($imageSize != 'original'){
                     $newDimensions = explode('x', $imageSizes[$imageSize]);
                     //}
                     $thumb->resize($newDimensions[0], $newDimensions[1]);
                     $thumb->save($cacheFile, 'png');
                 } catch (RuntimeException $e) {
                 }
             }
         }
         if (is_file($cacheFile)) {
             header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($cacheFile)) . ' GMT');
             readfile($cacheFile);
         } else {
             readfile($originalFile);
         }
     }
 }
 /**
  * Returns an instance of self
  * 
  * This is the usual singleton function that returns / instantiates the object
  * 
  * @return PhpThumb
  */
 public static function getInstance()
 {
     if (!self::$_instance instanceof self) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Example #3
0
 * 
 * @author Ian Selby <*****@*****.**>
 * @copyright Copyright (c) 2009 Gen X Design
 * @link http://phpthumb.gxdlabs.com
 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
 * @version 3.0
 * @package PhpThumb
 * @filesource
 */
// define some useful constants
define('THUMBLIB_BASE_PATH', dirname(__FILE__));
define('THUMBLIB_PLUGIN_PATH', THUMBLIB_BASE_PATH . '/thumb_plugins/');
define('DEFAULT_THUMBLIB_IMPLEMENTATION', 'gd');
/**
 * Include the PhpThumb Class
 */
require_once THUMBLIB_BASE_PATH . '/PhpThumb.inc.php';
/**
 * Include the ThumbBase Class
 */
require_once THUMBLIB_BASE_PATH . '/ThumbBase.inc.php';
/**
 * Include the GdThumb Class
 */
require_once THUMBLIB_BASE_PATH . '/GdThumb.inc.php';
/**
 * PhpThumbFactory Object
 * 
                imagecopy($this->workingImage, $this->workingImage, $x, $y_i - $y - 1, $x, $y, 1, 1);
            }
        }
    }
    /**
     * Converts a hex color to rgb tuples
     * 
     * @return mixed 
     * @param string $hex
     * @param bool $asString
     */
    protected function hex2rgb($hex, $asString = false)
    {
        // strip off any leading #
        if (0 === strpos($hex, '#')) {
            $hex = substr($hex, 1);
        } elseif (0 === strpos($hex, '&H')) {
            $hex = substr($hex, 2);
        }
        // break into hex 3-tuple
        $cutpoint = ceil(strlen($hex) / 2) - 1;
        $rgb = explode(':', wordwrap($hex, $cutpoint, ':', $cutpoint), 3);
        // convert each tuple to decimal
        $rgb[0] = isset($rgb[0]) ? hexdec($rgb[0]) : 0;
        $rgb[1] = isset($rgb[1]) ? hexdec($rgb[1]) : 0;
        $rgb[2] = isset($rgb[2]) ? hexdec($rgb[2]) : 0;
        return $asString ? "{$rgb[0]} {$rgb[1]} {$rgb[2]}" : $rgb;
    }
}
$pt = PhpThumb::getInstance();
$pt->registerPlugin('GdReflectionLib', 'gd');
Example #5
0
    /**
     * Utility function for checking if the server can generate thumbnails.
     *
     * @return bool True if it can, false otherwise.
     */
    public function thumbnailsAvailable()
    {
        if (!self::$_thumbnails) {
            require_once JPATH_LIBRARIES.'/koowa/components/com_files/helper/phpthumb/phpthumb.php';
            $pt = PhpThumb::getInstance();

            self::$_thumbnails = $pt->isValidImplementation(PhpThumbFactory::$defaultImplemenation) || $pt->isValidImplementation('gd');
        }

        return self::$_thumbnails;
    }