我是小佳 ,未注明原创的,均为转载。

PHP图片缩放函数

2007-03-08 13:37:13 / 个人分类:PHP杂谈

<?php
function imgageshow($link,$alt="",$x="",$y="",$class='')
{
 $size = GetImageSize($link);
 $width = $size[0];
 $height = $size[1];
 if($x!="" or $y!="")
 {
   if($width>$x){
  $temp=$x/$width;
  $width=$x;
  $height=$height*$temp;
  if($height>$y){
   $temp=$y/$height;
   $height=$y;
   $width=$width*$temp;
  }
   }elseif ($height>$y){
    $temp=$y/$height;
  $height=$y;
  $width=$width*$temp;
  if($width>$x){
   $temp=$x/$width;
   $width=$x;
   $height=$height*$temp;
  }
   }
   else{
  $width=$width;
  $height=$height;
   }
 }else{
   $width=$width;
   $height=$height;
 } 
 //echo "<img src="$link" width="$width" height="$height" alt="$alt">";
 if($class) echo "<img class='$class' src=\"$link\" width=\"$width\" height=\"$height\" alt=\"$alt\" border=0>";
 else echo "<img src=\"$link\" width=\"$width\" height=\"$height\" alt=\"$alt\" border=0>";
}

?>


TAG: PHP杂谈

Open Toolbar