CakePHP的phpThumb助手
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CakePHP的phpThumb助手相关的知识,希望对你有一定的参考价值。
<?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 { function __construct(){ $this->thumbPath = parent::url('/phpthumb/phpThumb.php'); } $width = "width="{$options['w']}""; }else{ $width = ''; } $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; } App::import('Helper', 'Html'); $html = new HtmlHelper(); $img = '/img/'.$img; } $src = parent::url($img); $output = $this->thumbPath . '?src='.$src .'&'.$urlOpt; return $output; } } ?>
以上是关于CakePHP的phpThumb助手的主要内容,如果未能解决你的问题,请参考以下文章