菜单

typo3切图

2010年06月11日 - typo3

固定宽高图片缩放,最好先等比压缩,再切割,否则先切的话如果图片大小有几M效率非常低,甚至卡死。以下是一个方法。

/**
* generate image tag
* return image tag (html)
*/
function getImage($imageName,$imageAlt,$param,$type)
{
$targetWidth = $this->lConf[‘imageFixWidth’] ? $this->lConf[‘imageFixWidth’] : 244;
$targetHeight =  $this->lConf[‘imageFixHeight’] ? $this->lConf[‘imageFixHeight’] : 114;

$imgSize = getimagesize($imageName);
list($imgWidth,$imgHeight) = $imgSize;
$imgAimRate = $targetWidth/$targetHeight;
if($imgWidth>$targetWidth && $imgHeight>$targetHeight)
{
$picConf = array();
$picConf[‘image.’][‘file’] = $imageName;
if($imgWidth/$imgAimRate <= $imgHeight)
{
$picConf[‘image.’][‘file.’][‘width’] = $targetWidth;
}
else
{
$picConf[‘image.’][‘file.’][‘height’] = $targetHeight;
}
$ImgCodeResource = $this->cObj->IMG_RESOURCE($picConf[‘image.’]);
}
$theImgCode = ”;
$imgpath = $ImgCodeResource?$ImgCodeResource:$imageName;
$imgSize = getimagesize($imgpath);
list($imgWidth,$imgHeight) = $imgSize;
$cutConf = array();
$cutConf[‘image.’][‘file’] = $imgpath;
if($imgWidth/$imgAimRate <= $imgHeight)
{
$cutConf[‘image.’][‘file.’][‘width’] = $imgWidth.’c’;
$cutConf[‘image.’][‘file.’][‘height’] = ($imgWidth/$imgAimRate).’c’;
}
else
{
$cutConf[‘image.’][‘file.’][‘height’] = $imgHeight.’c’;
$cutConf[‘image.’][‘file.’][‘width’] = ($imgHeight*$imgAimRate).’c’;
}
$cutConf[‘image.’][‘altText’] = $imageAlt ? $imageAlt : $filename;
$cutConf[‘image.’][‘titleText’] = $imageTitle ? $imageTitle : $filename;
$cutConf[‘image.’][‘imageLinkWrap’] = 0;
if($param == 1){$cutConf[‘image.’][‘file.’][‘params’] = ” -set option:modulate:colorspace rgb -modulate 100,0 “;}
if($type=1){
$theImgCode = $this->cObj->IMG_RESOURCE($cutConf[‘image.’]);
}else{
$theImgCode = $this->cObj->IMAGE($cutConf[‘image.’]);
}
return $theImgCode;
}

标签:

发表评论

电子邮件地址不会被公开。 必填项已用*标注