function heightlimit($imgurl) {
$maxheight = 250;
$imagesize = @getimagesize($imgurl);
if($imagesize[1] > $maxheight){
$height = $maxheight;
$width = @intval($imagesize[0]*$maxheight/$imagesize[1]);
return '[img='.$width.','.$height.']'.$imgurl.'[/img]';
} else{
return '[img]'.$imgurl.'[/img]';
}
}
function makethumb($srcFile,$dstFile){
$imgQuality=80;
$max_height=150;
$max_width=150;
//add by dream crop pic to a determind size
$data=GetImageSize($srcFile,&$info);
if($data[0]<=$data[1] and $data[1]>=$max_height){
$height=$max_height;
$width=intval($height*$data[0]/$data[1]);
}
if($data[0]>=$data[1] and $data[0]>=$max_width){
$width=$max_width;
$height=intval($width*$data[1]/$data[0]);
}
if($data[0]<$max_width and $data[1]<$max_height){
$width=$data[0];
$height=$data[1];
}
switch($data[2]){
case 1:
$im=@ImageCreateFromGIF($srcFile);
break;
case 2:
$im=@ImageCreateFromJPEG($srcFile);
break;
case 3:
$im=@ImageCreateFromPNG($srcFile);
break;
}
$srcW=ImageSX($im);
$srcH=ImageSY($im);
$ni=imagecreatetruecolor($width,$height);
imagecopyresampled($ni,$im,0,0,0,0,$width,$height,$srcW,$srcH);
switch($data[2]){
case 'gif':ImagePNG($ni,$srcFile, $imgQuality); break;
case 'jpeg':ImageJPEG($ni,$srcFile, $imgQuality); break;
case 'png':ImagePNG($ni,$srcFile, $imgQuality); break;
default:ImageJPEG($ni,$srcFile, $imgQuality); break;
// ImageJpeg($ni,$srcFile, $imgQuality);
}
// 如果需要输出到浏览器,那么将上一句改为ImageJpeg($ni);
// 如果需要其它格式的图片,改动最后一句就可以了
}
/** BEGIN function
*
* 作者:偶然
* 功能:生成缩略图
* 时间:2003.12.14
*
*/
function makethumb($srcFile,$dstFile,$dstW,$dstH,$rate=75,$markwords=null,$markimage=null)
{
$data = GetImageSize($srcFile);
switch($data[2])
{
case 1:
$im=@ImageCreateFromGIF($srcFile);
break;
case 2:
$im=@ImageCreateFromJPEG($srcFile);
break;
case 3:
$im=@ImageCreateFromPNG($srcFile);
break;
}
if(!$im) return False;
$srcW=ImageSX($im);
$srcH=ImageSY($im);
$dstX=0;
$dstY=0;
if ($srcW*$dstH>$srcH*$dstW)
{
$fdstH = round($srcH*$dstW/$srcW);
$dstY = floor(($dstH-$fdstH)/2);
$fdstW = $dstW;
}
else
{
$fdstW = round($srcW*$dstH/$srcH);
$dstX = floor(($dstW-$fdstW)/2);
$fdstH = $dstH;
}
$ni=ImageCreateTrueColor($dstW,$dstH);
$dstX=($dstX<0)?0:$dstX;
$dstY=($dstX<0)?0:$dstY;
$dstX=($dstX>($dstW/2))?floor($dstW/2):$dstX;
$dstY=($dstY>($dstH/2))?floor($dstH/s):$dstY;
$white = ImageColorAllocate($ni,255,255,255);
imagefilledrectangle($ni,0,0,$dstW,$dstH,$white);// 填充背景色
ImageCopyResized($ni,$im,$dstX,$dstY,0,0,$fdstW,$fdstH,$srcW,$srcH);
// 生成水印
if($markwords!=null)
{
imagestring($ni,2,3,3,$markwords,$white);
}
elseif($markimage!=null)
{
$wimage =imagecreatefromgif($markimage);
imagecopy($ni,$wimage,0,0,0,0,100,35);
imagedestroy($wimage);
}
ImageJpeg($ni,$dstFile,$rate);
imagedestroy($im);
imagedestroy($ni);
}
?>