一聚教程网:一个值得你收藏的教程网站

热门教程

php 生成缩略图程序[推荐]

时间:2022-07-02 09:24:03 编辑:袖梨 来源:一聚教程网

function ResizeImage($im,$maxwidth,$maxheight,$name){
$width = imagesx($im);
$height = imagesy($im);
if(($maxwidth && $width > $maxwidth) || ($maxheight && $height > $maxheight)){
if($maxwidth && $width > $maxwidth){
$widthratio = $maxwidth/$width;
$RESIZEWIDTH=true;
}
if($maxheight && $height > $maxheight){
$heightratio = $maxheight/$height;
$RESIZEHEIGHT=true;
}
if($RESIZEWIDTH && $RESIZEHEIGHT){
if($widthratio < $heightratio){
$ratio = $widthratio;
}else{
$ratio = $heightratio;
}
}elseif($RESIZEWIDTH){
$ratio = $widthratio;
}elseif($RESIZEHEIGHT){
$ratio = $heightratio;
}
$newwidth = $width * $ratio;
$newheight = $height * $ratio;
if(function_exists("imagecopyresampled")){
$newim = imagecreatetruecolor($newwidth, $newheight);
imagecopyresampled($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}else{
$newim = imagecreate($newwidth, $newheight);
imagecopyresized($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}
ImageJpeg ($newim,$smalladdrname.$name.".jpg");
ImageDestroy ($newim);
}else{
ImageJpeg ($im,$smalladdrname.$name.".jpg");
}
}

 

if($_FILES['image']['size']){
if($_FILES['image']['type'] == "image/pjpeg"){
$im = imagecreatefromjpeg($bigaddrname.$exname);
}elseif($_FILES['image']['type'] == "image/x-png"){
$im = imagecreatefrompng($bigaddrname.$exname);
}elseif($_FILES['image']['type'] == "image/gif"){
$im = imagecreatefromgif($bigaddrname.$exname);
}
if($im){
if(file_exists($smalladdrname.".jpg")){

unlink($smalladdrname.".jpg");
}
ResizeImage($im,$RESIZEWIDTH,$RESIZEHEIGHT,$smalladdrname);
ImageDestroy ($im);
}

热门栏目