Revision: 11471
Updated Code
at February 24, 2009 04:43 by ping_ch
Updated Code
<?php /** * phpThumb Helper * * @author Stefan Zollinger * @license GPL * * options: * w = max width of output thumbnail in pixels * h = max height of output thumbnail in pixels * wp = max width for portrait images * hp = max height for portrait images * wl = max width for landscape images * hl = max height for landscape images * ws = max width for square images * hs = max height for square images * f = output image format ("jpeg", "png", or "gif") * q = JPEG compression (1=worst, 95=best, 75=default) * sx = left side of source rectangle (default = 0) * (values 0 < sx < 1 represent percentage) * sy = top side of source rectangle (default = 0) * (values 0 < sy < 1 represent percentage) * sw = width of source rectangle (default = fullwidth) * (values 0 < sw < 1 represent percentage) * sh = height of source rectangle (default = fullheight) * (values 0 < sh < 1 represent percentage) * zc = zoom-crop. Will auto-crop off the larger dimension * so that the image will fill the smaller dimension * (requires both "w" and "h", overrides "iar", "far") * Set to "1" or "C" to zoom-crop towards the center, * or set to "T", "B", "L", "R", "TL", "TR", "BL", "BR" * to gravitate towards top/left/bottom/right directions * (requies ImageMagick for values other than "C" or "1") * bg = background hex color (default = FFFFFF) * bc = border hex color (default = 000000)* * * */ class ThumbHelper extends Helper { var $defaults = array('q'=>80, 'zc'=>'C' ); function __construct(){ $this->thumbPath = parent::url('/phpthumb/phpThumb.php'); } function image($img, $options=array(), $attributes=array()){ if(!empty($options['w'])){ $width = "width=\"{$options['w']}\""; }else{ $width = ''; } if(!empty($options['h'])){ $height = "height=\"{$options['h']}\""; }else{ $height = ''; } $attrs = ''; foreach($attributes as $key=>$value){ $attrs .= ' '.$key.'="'.$value.'"'; } $src = $this->url($img, $options); $output = "<img {$attrs} src=\"{$src}\" {$width} {$height} />"; return $output; } function url($img, $options=array()){ $options = array_merge($this->defaults, $options); $urlOpt = htmlentities(http_build_query($options)); App::import('Helper', 'Html'); $html = new HtmlHelper(); if(substr($img, 0, 1) != '/'){ $img = '/img/'.$img; } $src = parent::url($img); $output = $this->thumbPath . '?src='.$src .'&'.$urlOpt; return $output; } } ?>
Revision: 11470
Updated Code
at February 19, 2009 03:59 by ping_ch
Updated Code
<?php /** * phpThumb Helper * * @author Stefan Zollinger * @license GPL * * options: * w = max width of output thumbnail in pixels * h = max height of output thumbnail in pixels * wp = max width for portrait images * hp = max height for portrait images * wl = max width for landscape images * hl = max height for landscape images * ws = max width for square images * hs = max height for square images * f = output image format ("jpeg", "png", or "gif") * q = JPEG compression (1=worst, 95=best, 75=default) * sx = left side of source rectangle (default = 0) * (values 0 < sx < 1 represent percentage) * sy = top side of source rectangle (default = 0) * (values 0 < sy < 1 represent percentage) * sw = width of source rectangle (default = fullwidth) * (values 0 < sw < 1 represent percentage) * sh = height of source rectangle (default = fullheight) * (values 0 < sh < 1 represent percentage) * zc = zoom-crop. Will auto-crop off the larger dimension * so that the image will fill the smaller dimension * (requires both "w" and "h", overrides "iar", "far") * Set to "1" or "C" to zoom-crop towards the center, * or set to "T", "B", "L", "R", "TL", "TR", "BL", "BR" * to gravitate towards top/left/bottom/right directions * (requies ImageMagick for values other than "C" or "1") * bg = background hex color (default = FFFFFF) * bc = border hex color (default = 000000)* * * */ class ThumbHelper extends Helper { var $defaults = array('q'=>80, 'zc'=>'C' ); function __construct(){ $this->thumbPath = parent::url('/phpthumb/phpThumb.php'); } function image($img, $options=array()){ if(!empty($options['w'])){ $width = "width=\"{$options['w']}\""; }else{ $width = ''; } if(!empty($options['h'])){ $height = "height=\"{$options['h']}\""; }else{ $height = ''; } $src = $this->url($img, $options); $output = "<img src=\"{$src}\" {$width} {$height} />"; return $output; } function url($img, $options=array()){ $options = array_merge($this->defaults, $options); $urlOpt = http_build_query($options); App::import('Helper', 'Html'); $html = new HtmlHelper(); $src = parent::url($img); $output = $this->thumbPath . '?src='.$src .'&'.$urlOpt; return $output; } } ?>
Revision: 11469
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at February 6, 2009 10:06 by ping_ch
Initial Code
<?php /** * phpThumb Helper * * @author Stefan Zollinger * * options: * w = max width of output thumbnail in pixels * h = max height of output thumbnail in pixels * wp = max width for portrait images * hp = max height for portrait images * wl = max width for landscape images * hl = max height for landscape images * ws = max width for square images * hs = max height for square images * f = output image format ("jpeg", "png", or "gif") * q = JPEG compression (1=worst, 95=best, 75=default) * sx = left side of source rectangle (default = 0) * (values 0 < sx < 1 represent percentage) * sy = top side of source rectangle (default = 0) * (values 0 < sy < 1 represent percentage) * sw = width of source rectangle (default = fullwidth) * (values 0 < sw < 1 represent percentage) * sh = height of source rectangle (default = fullheight) * (values 0 < sh < 1 represent percentage) * zc = zoom-crop. Will auto-crop off the larger dimension * so that the image will fill the smaller dimension * (requires both "w" and "h", overrides "iar", "far") * Set to "1" or "C" to zoom-crop towards the center, * or set to "T", "B", "L", "R", "TL", "TR", "BL", "BR" * to gravitate towards top/left/bottom/right directions * (requies ImageMagick for values other than "C" or "1") * bg = background hex color (default = FFFFFF) * bc = border hex color (default = 000000)* * * */ class ThumbHelper extends Helper { var $defaults = array('q'=>80, 'zc'=>'C' ); function __construct(){ $this->thumbPath = DS.APP_DIR . '/phpthumb/phpThumb.php'; } function image($img, $options=array()){ if(!empty($options['w'])){ $width = "width=\"{$options['w']}\""; }else{ $width = ''; } if(!empty($options['h'])){ $height = "height=\"{$options['h']}\""; }else{ $height = ''; } $src = $this->url($img, $options); $output = "<img src=\"{$src}\" {$width} {$height} />"; return $output; } function url($img, $options=array()){ $options = array_merge($this->defaults, $options); $urlOpt = http_build_query($options); App::import('Helper', 'Html'); $html = new HtmlHelper(); $src = DS.APP_DIR.DS.'webroot'.DS.$img; $output = $this->thumbPath . '?src='.$src .'&'.$urlOpt; return $output; } } ?>
Initial URL
phpthumbhelper
Initial Description
Initial Title
phpThumb Helper for CakePHP
Initial Tags
cakephp
Initial Language
PHP