-
- /**
- * Thumbnail Image Linux Image Server
- * edit bbs.it-home.org
- */
- $picID=$_GET['imgID'];
- $picTypes=".".$_GET['imgType'];
- $picWidth= $_GET['ImgWidth'];
- if($picID!="")
- {
- //The request is for a small picture
- if($picWidth>0){
- //If the small picture exists
- if(file_exists($ picID."_".$picWidth.$picTypes))
- {
- outputImg($picID."_".$picWidth.$picTypes);
- }else
- {
- if(file_exists($picID."_0".$ picTypes)){
- //If the thumbnail does not exist, generate the thumbnail directly
- resizeImg($picID."_0".$picTypes,$picWidth,$picWidth,$picID."_".$picWidth.$picTypes);
- //Output
- outputImg($picID."_".$picWidth.$picTypes);
- }else
- {
- //If the large image does not exist
- resizeImg('noDefaultImage.gif',$picWidth,$picWidth,noDefaultImage. "_".$picWidth.".gif");
- //Output
- outputImg($picID."_".$picWidth.$picTypes);
- }
- }
- }
- //Determine whether a large image exists in the file
- if(file_exists($picID."_0".$picTypes))
- {
- $img_file = $picID."_0".$picTypes;
- outputImg($img_file);
- }
- else
- {
- //if it does not exist Image
- $img_file = 'noDefaultImage.gif';
- outputImg($img_file);
- }
- }
- //Output image
- function outputImg($img_file)
- {
- $fp = fopen($img_file, 'rb');
- $content = fread($fp, filesize($img_file)); //Binary data
- fclose($fp);
- header('Content-Type: image/gif');
- echo $content;
- }
- / **
- * Generate thumbnails
- * $srcName---- is the original image path
- * $newWidth, $newHeight---- are the maximum width and height of the thumbnail respectively
- * $newName---- is the thumbnail file name ( including path)
- * @param string $srcName
- * @param int $newWidth
- * @param int $newHeight
- * @param string $newName
- * return viod
- */
- function resizeImg($srcName,$newWidth,$newHeight,$newName="")
- {
- if($newName=="")
- {
- $nameArr=explode('.', $srcName);
- $expName=array_pop($nameArr);
- $expName=$expName;
- array_push($nameArr,$expName);
- $newName = implode('.',$nameArr);
- }
- $info = "";
- $data = getimagesize($srcName,$info);
- switch ($data[2])
- {
- case 1:
- if(!function_exists("imagecreatefromgif")){
- echo "Your GD The library cannot use images in GIF format, please use Jpeg or PNG format! return ";
- exit();
- }
- $im = ImageCreateFromGIF($srcName);
- break;
- case 2:
- if(!function_exists("imagecreatefromjpeg")){
- echo "Your GD library cannot use jpeg format For pictures, please use pictures in other formats!返回";
- exit();
- }
- $im = ImageCreateFromJpeg($srcName);
- break;
- case 3:
- $im = ImageCreateFromPNG($srcName);
- break;
- }
- $srcW=ImageSX($im);
- $srcH=ImageSY($im);
- $newWidthH=$newWidth/$newHeight;
- $srcWH=$srcW/$srcH;
- if($newWidthH<=$srcWH){
- $ftoW=$newWidth;
- $ftoH=$ftoW*($srcH/$srcW);
- }
- else{
- $ftoH=$newHeight;
- $ftoW=$ftoH*($srcW/$srcH);
- }
- if($srcW>$newWidth||$srcH>$newHeight)
- {
- if(function_exists("imagecreatetruecolor"))
- {
- @$ni = ImageCreateTrueColor($ftoW,$ftoH);
- if($ni) ImageCopyResampled($ni,$im,0,0,0,0,$ftoW,$ftoH,$srcW,$srcH);
- else
- {
- $ni=ImageCreate($ftoW,$ftoH);
- ImageCopyResized($ni,$im,0,0,0,0,$ftoW,$ftoH,$srcW,$srcH);
- }
- }
- else
- {
- $ni=ImageCreate($ftoW,$ftoH);
- ImageCopyResized($ni,$im,0,0,0,0,$ftoW,$ftoH,$srcW,$srcH);
- }
- if(function_exists('imagejpeg')) ImageJpeg($ni,$newName);
- else ImagePNG($ni,$newName);
- ImageDestroy($ni);
- }
- ImageDestroy($im);
- }
- ?>
复制代码
|