-
- Header("Content-type: image/png") /*???? ???? ????? ????*/
- $ im = imagecreate(400, 300); /*??? ?? ??*/
- $gray = ImageColorAllocate($im, 235, 235, 235)
- $pink = ImageColorAllocate($im , 255, 128, 255);
- $fontfile = "simkai.ttf"
- /* $fontfile ?? ??? ?? ??? ?? simhei.ttf(??), SIMKAI.TTF( italic), SIMFANG.TTF(??? ??), SIMSUN.TTC(??? ? ????) ? GD?? ???? ?? ??? ??*/
- $str = iconv('GB2312','UTF-8', '??? ????'); /*gb2312 ?? ??? UTF-8 ??? ??*/
- ImageTTFText($im, 30, 0, 100, 200, $pink, $fontfile, $str); /* ??? ???? ??*/
- Imagepng($im)
- ImageDestroy($im)
- ?>
-
?? ??
?? 2, PHP ??? ???? ??.
- // *********************** ***************** //
- // ??: ???? ??? ??
- // ????: $img ??? ?? ??
- // $new_img ??? ?? ???? ??, ?? ??? ???? ???? ???? ??
- // $text string content
- // text_size ??? ??
- // text_angle ?? ??? ?? ??
- // text_x ??? ?? x ??
- // text_y ??? ?? y ??
- // $text_font ?? ?? ??
- // $r, $g, $b ??? ?? RGB ?
- // *** *********************************** //
- ?? img_text($img, $new_img , $ text, $text_size, $text_angle, $text_x, $text_y, $text_font, $r, $g, $b){
- $text=iconv("gb2312","UTF-8",$text) ; ??>Header("??? ??: image/gif");
- $im = @imagecreatefromstring(file_get_contents($img)) ?? die("???? ?? ?????!")
- $color = ImageColorAllocate( $im, $r,$g,$b);
- //ImageTTFText(int im, int size, int angle, int x, int y, int col, ??? ?? ??, ??? ???):
- / / ? ??? TTF(TrueType Fonts) ?? ???? ???? ???.
- //????: size? ??? ?????.
- // angle? ??? ???, ?? ???? ?????. 0?? ??(???? ?????), 90?? ????? ??????. top ;
- // ? ???? x? y? ???? ?? ????(??? ?? ?????).
- // col? ???? ?????. Fontfile? ?? ??? ?????.
- / /text? ??? ?????.
- ImageTTFText($im, $text_size, $text_angle, $text_x, $text_y, $color, $text_font, $text)
- if ($new_img==""):
- ImageGif($im ); // ???? ???? ?? ??? ???.
- ImageGif($im,$new_img) // ???? ????? ???? ????.
- ImageDestroy( $im); / /??? ??, ??? ?? ??
- ?>
-
-
- ?? ??
-
-
?? 3, PHP ??? ????? PHP ??? ???? ??? ?????.
-
- /*
- * ??: PHP ??? ????(????? ??? ?? ???? ???)
- * ????:
- * $groundImage ?? ???, ? ????? ??? ???? ?? GIF, JPG ? PNG ??? ?????.
- * $waterPos ???? ??? 10?? ???? 0? ?? ?????. * 1? ?? ??, 2? ??? ??, 3? ??? ???? ?????.
- * 4? ?? ??, 5? ??, 6? ?????. right;
- * 7? ?? ??, 8? ?? ??, 9? ??? ??????.
- * $waterImage ??? ????, ? ??? ?? ???? ??????. ????? ?? GIF, JPG ? PNG ??? ?????.
- * $waterText ??? ????, ? ???? ????? ????, ASCII ??? ????, ???? ???? ????.
- * $textFont ??? ??. , ?? 1, 2, 3, 4 ?? 5, ???? 5???.
- * $textColor ??? ??, ?? 16?? ?? ?, ???? #FF0000(???)???. GD 2.0 ??, FreeType ??, GIF ??, GIF ??, JPG, PNG
- * $waterImage? $waterText? ??? ???? ?? ?? ?? ????. ?, $waterImage? ?? ?????.
- * $waterImage? ???? $waterString, $stringFont ? $stringColor ????? ???? ????.
- * ????? ??? ???? ???? $groundImage? ?????.
- * ???: longware @ 2004-11-3 14:15:13
- */
- ?? imageWaterMark($groundImage,$waterPos=0,$waterImage=””,$waterText=””,$ textFont=5,$textColor=”#FF0000″)
- {
- $isWaterImage = FALSE;
- $formatMsg = “? ?? ??? ?? ???? ?? ??? ?? ?????? ???? ???? GIF? ?????. ?? JPG, PNG ?????.”;
- //???? ?? ??
- if(!emptyempty($waterImage) && file_exists($waterImage))
- {
- $isWaterImage =
- $water_info = getimagesize($ waterImage );
- $water_w = $water_info[0];//???? ??? ?? ????
- $water_h = $water_info[1];//???? ??? ?? ????
- switch($ water_info[2 ])//???? ??? ?? ????
- {
- case 1:$water_im = imagecreatefromgif($waterImage);break
- case 2:$water_im = imagecreatefromjpeg($waterImage); break;
- ?? 3:$water_im = imagecreatefrompng($waterImage);break;
- default:die($formatMsg)
- }
- }//?? ??? ??
- if(!emptyempty( $groundImage) && file_exists($groundImage))
- {
- $ground_info = getimagesize($groundImage)
- $ground_w = $ground_info[0];// ?? ???
- $ground_h = $ground_info[1];//?? ??? ?? ????
- switch($ground_info[2])//?? ??? ?? ????
- {
- ?? 1:$ground_im = imagecreatefromgif($groundImage) ;break;
- ?? 2:$ground_im = imagecreatefromjpeg($groundImage);break
- ?? 3:$ground_im = imagecreatefrompng($groundImage);break; >default:die($formatMsg);
- }
- }
- else
- {
- die("?????? ? ??? ???? ????! ”);
- //???? ??
- if($isWaterImage)//?? ????
- {
- $w = $water_w
- $h = $water_h; >$label = "???"
- }
- else//??? ????
- {
- $temp = imagettfbbox(ceil($textFont*5),0,"./cour.ttf" , $waterText);//???? ??? ???? ??? ?? ????
- $w = $temp[2] - $temp[6]
- $h = $temp[3] - $temp[7] ;
- unset($temp);
- $label = "??? ??"
- }
- if( ($ground_w<$w) || ($ground_h<$h) )
- {
- echo "????? ???? ?? ???? ??? ?? ".$label." ?????? ??? ????? ??? ? ????! ”;
- return;
- }
- switch($waterPos)
- {
- case 0://random
- $posX = rand(0,($ground_w - $w)) ;
- $posY = rand(0,($ground_h - $h));
- break
- ?? ??? 1://1???
- $posY; = 0;
- break;
- case 2://2? ?? ??? ????.
- $posX = ($ground_w - $w) / 2
- $posY = 0;
- ??? 3://3? ??? ??
- $posX = $ground_w - $w;
- $posY = 0
- break
- ???; left
- $posX = 0;
- $posY = ($ground_h - $h) / 2
- break
- case 5://5? ??? ???
- $posX = ($ground_w - $w) / 2;
- $posY = ($ground_h - $h) / 2
- break
- case 6://6? ??? ??
- $posX = $ ground_w - $ w;
- $posY = ($ground_h - $h) / 2;
- break
- case 7://7? ?? ??
- $posX = 0; posY = $ground_h - $h;
- break;
- case 8://8? ?? ??? ?????.
- $posX = ($ground_w - $w) / 2; $ h;
- break;
- case 9://9? ??? ??
- $ground_w - $w
- $posY = $ground_h -
- break; ??>default://random
- $posX = rand(0,($ground_w - $w))
- $posY = rand(0,($ground_h - $h))
- break ;
- }
- //???? ?? ?? ?? ??
- imagealphablending($ground_im, true)
- if($isWaterImage)//??? ????
- {
- imagecopy($ ground_im , $water_im, $posX, $posY, 0, 0, $water_w,$water_h);//????? ?? ??? ??
- }
- else//??? ????
- {
- if( !emptyempty($textColor) && (strlen($textColor)==7) )
- {
- $R = hexdec(substr($textColor,1,2))
- $G = hexdec(substr ( $textColor,3,2));
- $B = hexdec(substr($textColor,5));
- }
- else
- {
- die("???? ??? ?? ?? ???? ????!");
- }
- imagestring( $ground_im, $textFont, $posX, $posY, $waterText, imagecolorallocate($ground_im, $R, $G, $B));
- }
- //生成水印后? ??
- @unlink($groundImage);
- switch($ground_info[2])//取得背景圖文字格式
- {
- case 1:imagegif($ground_im,$groundImage);break;
- ?? 2:imagejpeg($ground_im,$groundImage);break;
- ?? 3:imagepng($ground_im,$groundImage);break;
- ???:die($errorMsg);
- }
- //釋放內(nèi)存
- if(isset($water_info)) unset($water_info);
- if(isset($water_im)) imagedestroy($water_im);
- ?? ??($ground_info);
- imagedestroy($ground_im);
- }
- //————————————————————————————
- $id=$_REQUEST['id' ];
- $num = count($_FILES['userfile']['name']);
- print_r($_FILES['userfile']);
- print_r($_FILES['??? ??']['??']);
- ?? $num;
- ?? “
”;
- if(isset($id)){
- for($i=0;$i<$id;$i ){
- if(isset($_FILES) && !emptyempty($_FILES[' userfile']) && $_FILES['userfile']['size']>0)
- {
- $uploadfile = “./”.time().”_”.$_FILES['userfile' ][??][$i];
- ?? “
”;
- echo $uploadfile;
- if (copy($_FILES['userfile']['tmp_name'][$i], $uploadfile))
- {
- echo “??
”; $waterImage=”logo_ok1.gif”;//WaterMark($uploadfile,9,$waterImage)
- echo “
";
- }
- else
- {
- echo “??
”;
- }
- }
- }
- }
- ?>
-
- for($a=0;$a<$id;$a ){
- echo “文件: ? ??=”userfile[]” type=”file”> ;
”;
- }
- ?>
- ? ??=”??” ?=”上傳”>
-
-
- 復代碼
-
-
?? 4
??? ???? ??
-
- /*-----
- **??: ??? ???? ?? ????? ???? ? ?????( ??? ?? ??? ???? ??) ??? ????
- ? ???? ???.
- **???: 2007-10-09
- **?????: 2007-10-09
- **??: 1. ?? gd ????? ??, iconv ?? ??(php5? ?? ???? ?? ??? ?? ??)
- 2. jpg/jpeg/gif/png ? ?? ??? ????? ???? ?? ??? ???? ????.
- 3. ???? ?? ????? ??? ?? ???? ???.
- 4. ?? ?:
- $objImg = new MyWaterDownChina()
- $objImg->Path = "images/ ";
- $objImg->FileName = "1.jpg";
- $objImg->Text = "HAHAKONGJIANHTTP://HI.BAIDU.COM/LYSONCN";
- $objImg-> Font = "./font/simhei.ttf";
- $objImg-> ;Run()
- **?? ??:
- ---------------* /
- class MyWaterDownChina{
- var $Path = "./"; //? ???? ???? ???? ???? ??? ?? ????? ?? ??
- var $FileName = ""; //?? ??(?: "1.jpg")
- var $Text = ""; //Picture ??? ???? ???? ???? ?????.
- var $TextColor = "#ffffff" // ??? ??, gif ??? ?? ?? ??? ???? ?????.
- var $TextBgColor = "#000000" / /??? ?? ??? ??
- var $Font = "c:// windows//fonts//simhei.ttf"; //?? ?? ????, ?? ??
- var $OverFlag = true; // ?? ???? ???? ??, ???? ???????. ???? ?? ?? "_water_down "? ?? ??? ?? ?? ?? ???? ?????. ?: "1.jpg" => "1_water_down.jpg" var $BaseWidth = 200; //?? ???? ?? ??? ??? >=200??? ???. ???? ?????.
- //-------------
- //??: ??? ???(php5.0 ??)
- //????: ??
- / /??: ??
- function __construct(){;}
- //------------
- //??: ??? ???(?? php5.0 ??)
- //????: ??
- //??: ??
- ?? __destruct(){;}
- //------ -------- --------
- //??: ??? ??? ???? ???? ????? ?????
- //????: ??
- //??: ??
- function Run()
- {
- if($this->FileName == "" || $this->Text == "")
- return
- //GD ????? ?? ?? ??
- if(false == function_exists("gd_info"))
- {
- echo "GD ?????? ???? ???? ?? ?? ???? ????? ??? ? ????."
- return; >}
- //?? ? ?? ??? ?? ?? ??
- $arr_in_name =explore(".",$this->FileName)
- //
- $inImg = $this-> ;Path.$ this->FileName
- $outImg = $inImg;
- $tmpImg = $this->Path.$arr_in_name[0]."_tmp.".$arr_in_name[1]; /????? ??? ??, ?? ??
- if(!$this->OverFlag)
- $outImg = $this->Path.$arr_in_name[0]."_water_down.".$arr_in_name[1];
- //??? ?? ?? ??
- if(!file_exists($inImg))
- return
- //??? ?? ????
- $groundImageType = @getimagesize($inImg) ;
- $imgWidth = $groundImageType[0];
- $imgHeight = $groundImageType[1]
- $imgType = $groundImageType[2]
- if($imgWidth < $this-> ;BaseWidth) //?? ?? ??, ???? ??
- return
- //??? jpg/jpeg/gif/png? ?? ?? ???? ??
- switch($imgType)
- {
- ?? 1:
- $ image = imagecreatefromgif($inImg);
- $this->TextBgColor = "#ffffff"; //gif ???? ??? ???? ????? ???? ???? ??
- break;
- ?? 2:
- $image = imagecreatefromjpeg($inImg);
- break;
- ?? 3:
- $image = imagecreatefrompng($inImg); ??>break;
- ???:
- return
- break
- }
- //?? ??
- $color = @imagecolorallocate($image,hexdec(substr($this->) ;TextColor,1,2)),hexdec(substr( $this->TextColor,3,2)),hexdec(substr($this->TextColor,5,2))) //??? ??
- //??? ??? ? ??? ??
- $newHeight = $imgHeight 20;
- $objTmpImg = @imagecreatetruecolor($imgWidth,$newHeight)
- $colorBg = @imagecolorallocate($objTmpImg,hexdec(substr($this->TextBgColor,1,2)),hexdec(substr($this->TextBgColor,3,2)),hexdec(substr($this->TextBgColor ,5,2))); //???
- //???? ??? ???
- @imagefill ($objTmpImg,0,0,$colorBg)//?? ??? ?? ?? ????
- @imagecopy($objTmpImg,$image, 0,0,0,0,$imgWidth,$imgHeight)
- //??? ???? ??? ?? ??
- $objText = $this->createText($this->Text);//??? ???? ???? ?? ??
- $x = 5
- $y = $newHeight-5; ??>//??? ???? ??
- @imagettftext($objTmpImg, 10,0,$x,$y,$color,$this->Font,$objText)
- //? ?? ??, ?? ??
- switch($imgType)
- {
- ?? 1:
- imagegif($objTmpImg,$tmpImg)
- break;
- ?? 2:
- imagejpeg($objTmpImg ,$tmpImg);
- break;
- imagepng($objTmpImg,$tmpImg);
- default:
- return; >}
- //??? ??
- @imagedestroy($ objTmpImg)
- @imagedestroy($image)
- //?? ?? ???
- if($this->OverFlag)
- {
- //?? ??? ????
- @unlink ($inImg)
- @rename($tmpImg,$outImg)
- else
- {
- //?? ???? ???? ???
- @rename($tmpImg,$outImg )
- }
- }
- //---------
- //Function : ???? ??? ?? ??
- //????: ??
- //Return : ???? ??? ?? ??
- function createText($instring)
- {
- $outstring=""
- $ max=strlen($instring);
- for($i=0; $i<$max;$i )
- {
- $h=ord($instring[$i])
- if($h>=160 && $i<$max-1)
- {
- $outstring .= "".base_convert(bin2hex(iconv("gb2312","ucs-2",substr( $instring,$i,2)),16,10)."; "
- $i ;
- }
- else
- {
- $outstring .= $instring[$i ];
- }
- }
- return $outstring;
- }
- }//class
- ?>
-
-
- ?? ??
-
-
-
-
-
-
-
|