php 生成缩略图程序_PHP教程

php教程评论171 views阅读模式

php教程 生成缩略图程序

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

企鹅博客
  • 本文由 发表于 2020年5月7日 08:56:10
  • 转载请务必保留本文链接:https://www.qieseo.com/307880.html

发表评论