国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

PHP實現上傳文件生成小圖加文字的實例

2024-05-04 23:03:32
字體:
來源:轉載
供稿:網友

<?
//自動縮圖$srcfile原文件,大圖;$photo_small目標文件,小圖;$dstw,$dsth是小圖的寬,高。
function makethumb($srcfile,$photo_small,$dstw,$dsth) {
 $data = getimagesize($srcfile);
 switch ($data[2]) {
 case 1: //圖片類型,1是gif圖
  $im = @imagecreatefromgif($srcfile);
  break;
 case 2: //圖片類型,2是jpg圖
  $im = @imagecreatefromjpeg($srcfile);
  break;
 case 3: //圖片類型,3是png圖
  $im = @imagecreatefrompng($srcfile);
  break;
 }
 $srcw=imagesx($im);//原始圖片的寬度,也可以使用$data[0]
 $srch=imagesy($im);//原始圖片的高度,也可以使用$data[1]
 $srcx=0;//來源圖的坐標x,y
 $srcy=0;
 if(($srcw/$dstw)>($srch/$dsth)){//得出要生成圖片的長寬
  $dstw2=$dstw;//輸出圖片的寬度、高度
  $dsth2=$srch*$dstw/$srcw;
  $dstx=0;//輸出圖形的坐標x,y
  $dsty=($dsth-$dsth2)/2;
 }
 else{
  $dsth2=$dsth;//輸出圖片的寬度、高度
  $dstw2=$srcw*$dstw/$srch;
  $dstx=($dstw-$dstw2)/2;//輸出圖形的坐標x,y
  $dsty=0;
 }
 $ni=imagecreatetruecolor($dstw,$dsth);//imagecreate($dstw,$dsth);畫出空白花布的大小
 $colorbody=imagecolorallocate($ni,235,234,233);//定義背景顏色
 imagefill($ni,0,0,$colorbody);//填充背景顏色
 imagecopyresized($ni,$im,$dstx,$dsty,$srcx,$srcy,$dstw2,$dsth2,$srcw,$srch);
 imagejpeg($ni,$photo_small);
 //imagejpeg($ni); //在顯示圖片時用,把注釋取消,可以直接在頁面顯示出圖片。
}
//生成帶有版權信息的圖片
function makecopyright($srcfile,$dstfile,$dstw,$dsth){
 $data = getimagesize($srcfile);
 switch ($data[2]) {
 case 1: //圖片類型,1是gif圖
  $srcimg = @imagecreatefromgif($srcfile);
  break;
 case 2: //圖片類型,2是jpg圖
  $srcimg = @imagecreatefromjpeg($srcfile);
  break;
 case 3: //圖片類型,3是png圖
  $srcimg = @imagecreatefrompng($srcfile);
  break;
 }
 $srcw=imagesx($srcimg);//原始圖片的寬度,也可以使用$data[0]
 $srch=imagesy($srcimg);//原始圖片的高度,也可以使用$data[1]
 
 if(($srcw/$dstw)>($srch/$dsth)){//得出要生成圖片的長寬
  $dstw2=$dstw;//輸出圖片的寬度、高度
  $dsth2=$srch*$dstw/$srcw;
 }
 else{
  $dsth2=$dsth;//輸出圖片的寬度、高度
  $dstw2=$srcw*$dstw/$srch;
 }
 $dstimg=imagecreatetruecolor($dstw2,$dsth2);//畫出空白花布的大小
 imagecopyresized($dstimg,$srcimg,0,0,0,0,$dstw2,$dsth2,$srcw,$srch);
 //定義要寫入的文字
 $word="http://www.survivalescaperooms.com";//文字
 $font=5;//字體
 $wordcolor=imagecolorallocate($dstimg,0x08,0x00,0x00);//顏色
 $wordx=$dstw2-200;//x坐標
 $wordy=$dsth2-20;//y坐標
 imagestring($dstimg,$font,$wordx,$wordy,$word,$wordcolor);//寫入文字
 imagejpeg($dstimg,$dstfile);
 //imagejpeg($ni); //在顯示圖片時用,把注釋取消,可以直接在頁面顯示出圖片。
}

//調用
$srcfile=$pimg_name;//取得文件擴展名:
 $type=substr(strrchr($pimg_name,"."),1);
 $photo_id=date("ymdhis");
 $dst_small=$photo_id."_s.".$type; //小圖
 $dst_big=$photo_id."_b.".$type; //大圖
 makethumb($pimg,"../cpzs/".$dst_small,120,90);//120,90為小圖寬,高
 makecopyright($pimg,"../cpzs/".$dst_big,600,480);
 //if(copy($pimg,"../cpzs/".$dst_big))
    //     echo "文件上傳成功<br>";
    //else
    //    echo "文件上傳失敗<br>";
?>



收集最實用的網頁特效代碼!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 常州市| 建瓯市| 宁强县| 呼图壁县| 鄂温| 凌海市| 昭通市| 太湖县| 化隆| 秭归县| 盐源县| 三原县| 泸州市| 新绛县| 德格县| 安义县| 体育| 徐水县| 理塘县| 长宁区| 黑水县| 错那县| 会昌县| 河池市| 公安县| 汉寿县| 河池市| 兰坪| 章丘市| 安丘市| 周宁县| 乌兰察布市| 化德县| 洛川县| 威海市| 松潘县| 托克托县| 宁强县| 南城县| 牟定县| 黔西|