日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

Linux图片马PHP,php 根据请求生成缩略图片保存到Linux图片服务器的代码

發布時間:2024/9/27 linux 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Linux图片马PHP,php 根据请求生成缩略图片保存到Linux图片服务器的代码 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這個功能,有點類似圖片站點分離的操作,就是將圖片單獨架設在一臺服務器上,有興趣的朋友,好好研究下吧。

代碼如下:

復制代碼 代碼示例:

/**

* 縮略圖片 Linux圖片服務器

* edit www.jbxue.com

*/

$picID=$_GET['imgID'];

$picTypes=".".$_GET['imgType'];

$picWidth=$_GET['ImgWidth'];

if($picID!="")

{

//請求的是小圖

if($picWidth>0){

//如果小圖存在

if(file_exists($picID."_".$picWidth.$picTypes))

{

outputImg($picID."_".$picWidth.$picTypes);

}else

{

if(file_exists($picID."_0".$picTypes)){

//如果不存在小圖直接生成小圖

resizeImg($picID."_0".$picTypes,$picWidth,$picWidth,$picID."_".$picWidth.$picTypes);

//輸出

outputImg($picID."_".$picWidth.$picTypes);

}else

{

//如果大圖不存在

resizeImg('noDefaultImage.gif',$picWidth,$picWidth,noDefaultImage."_".$picWidth.".gif");

//輸出

outputImg($picID."_".$picWidth.$picTypes);

}

}

}

//判斷文件是否存在大圖

if(file_exists($picID."_0".$picTypes))

{

$img_file = $picID."_0".$picTypes;

outputImg($img_file);

}

else

{

//如果不存在圖片

$img_file = 'noDefaultImage.gif';

outputImg($img_file);

}

}

//輸出圖片

function outputImg($img_file)

{

$fp = fopen($img_file, 'rb');

$content = fread($fp, filesize($img_file)); //二進制數據

fclose($fp);

header('Content-Type: image/gif');

echo $content;

}

/**

* 生成縮略圖

* $srcName----為原圖片路徑

* $newWidth,$newHeight----分別縮略圖的最大寬,高

* $newName----為縮略圖文件名(含路徑)

* @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 "你的GD庫不能使用GIF格式的圖片,請使用Jpeg或PNG格式!返回";

exit();

}

$im = ImageCreateFromGIF($srcName);

break;

case 2:

if(!function_exists("imagecreatefromjpeg")){

echo "你的GD庫不能使用jpeg格式的圖片,請使用其它格式的圖片!返回";

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

}

?>

總結

以上是生活随笔為你收集整理的Linux图片马PHP,php 根据请求生成缩略图片保存到Linux图片服务器的代码的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。