Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function render( $image, $params ) {
- //Set defaults
- $path = '';
- $width = 150;
- $height = 225;
- $quality = 75;
- $extension = 'jpg';
- //Extract Parameters
- if( isset( $params[ 'path' ] ) ) {
- $path = $params[ 'path' ] . DS;
- }
- if( isset( $params[ 'width' ] ) ) {
- $width = $params[ 'width' ];
- }
- if( isset( $params[ 'height' ] ) ) {
- $height = $params[ 'height' ];
- }
- if( isset( $params[ 'quality' ] ) ) {
- $quality = $params[ 'quality' ];
- }
- if( isset( $params[ 'extension' ] ) ) {
- $extension = $params[ 'extension' ];
- }
- //import phpThumb class with CakePHP
- App::import( 'Vendor', 'phpthumb', array( 'file' => 'phpThumb' . DS . 'phpthumb.class.php' ) );
- $thumbNail = new phpthumb;
- //WWW_ROOT and DS are CakePHP global for web root folder and Directory Seperator
- $thumbNail->src = WWW_ROOT . 'img' . DS . $path . $image;
- $thumbNail->w = $width;
- $thumbNail->h = $height;
- $thumbNail->q = $quality;
- $thumbNail->config_imagemagick_path = '/usr/bin/convert';
- $thumbNail->config_prefer_imagemagick = false;
- $thumbNail->config_output_format = $extension;
- $thumbNail->config_error_die_on_error = true;
- $thumbNail->config_document_root = '';
- //APP is a CakePHP global for the APP folder
- $thumbNail->config_temp_directory = APP . 'tmp';
- $thumbNail->config_cache_directory = WWW_ROOT . 'img' . DS . 'thumbs' . DS;
- $thumbNail->config_cache_disable_warning = true;
- $cacheFilename = $image;
- $thumbNail->cache_filename = $thumbNail->config_cache_directory . $cacheFilename;
- if( !is_file( $thumbNail->cache_filename ) ) {
- if( $thumbNail->GenerateThumbnail() ) {
- $thumbNail->RenderToFile( $thumbNail->cache_filename );
- }
- }
- if( is_file( $thumbNail->cache_filename ) ) {
- //File is a CakePHP Class that help manipulating files, I use it here to get the "last change date"
- $fullSizedImage = new File( $thumbNail->src );
- $thumbNailImage = new File( $thumbNail->cache_filename );
- //update thumbnail if original one has been updated
- if( $fullSizedImage->lastChange() > $thumbNailImage->lastChange() ) {
- if( $thumbNail->GenerateThumbnail() ) {
- $thumbNail->RenderToFile( $thumbNail->cache_filename );
- }
- }
- return $cacheFilename;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement