phpstudy_php 生成缩略图程序

更新时间:2016-06-14    来源:代码生成    手机版     字体:

【www.bbyears.com--代码生成】

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);
}

本文来源:http://www.bbyears.com/wangyetexiao/24608.html

猜你感兴趣

热门标签

更多>>

本类排行