經典的PHP縮圖產生程式,基於GD函式庫,可指定產生路徑及產生目標的寬高細節 使用方法: 在支援GD函式庫的PHP環境,將下列程式碼另存為resize.php測試
經典的PHP縮圖產生程式,基於GD函式庫,可指定產生路徑及產生目標的寬高細部
使用方法: 在支援GD函式庫的PHP環境,將下列程式碼另存為resize.php測試
複製程式碼 程式碼如下:
$FILENAME="image_name";
// 生成圖片的寬度$RESIZEWIDTH=400;
// 產生圖片的高度
$RESIZEHEIGHT=400;
//產生圖片的路徑
$uploaddir="c:/winnt/temp"; ResizeImage($im,$maxwidth,$maxheight,$name){
global $uploaddir;
$width = imagesx($im);
$height (($maxwidth && $width > $maxwidth) || ($maxheight && $height > $maxheight)){
if($maxwidth && 但是$$widthm> width;
$RESIZEWIDTH=true;
}
if($maxheight && $height > $maxheight){
$heightratioHE =$maxheight 🎜>}
if($RESIZEWIDTH && $RESIZEHEIGHT){
if($widthratio $ratio=rat $widm=rat ;
}
}elseif($RESIZEWIDTH){
$ratio = $widthratio;
}elseif($RESIZEHEIGHT){$rat> $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{ $width, $height);
}else{ $ );
imagecopyresized($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
} , $width, $height);
} . name . ".jpg");
ImageDestroy ($newim);
}else{
ImageJpeg ($im,$uploaddir.$name)> ".jpg"); }
if($_FILES['image']['size']){
if($_FILES['image']['type'] == "image/pjpeg"){
$ im = imagecreatefromjpeg($_FILES['image']['tmp_name']);
}elseif($_FILES['image']['type'] == "image/x-png"){
$im = imagecreatefrompng($_FILES['image']['tmp_name']);
}elseif($_FILES['image']['type'] == "image/gif"){
$ im = imagecreatefromgif($_FILES['image']['tmp_name']);
}
if($im){
if(file_exists("$FILENAME.jpg")){ unlink("$FILENAME.jpg");
}
ResizeImage($im,$RESIZEWIDTH,$RESIZEHEIGHT,$FILENAME);
ImageDestroy ($im); 🎜>?>
">