<?php /*給圖片加文字和圖片水印的方法*/ $dst_path = './1.png'; //選用添加的原圖 $dst = imagecreatefromstring(file_get_contents($dst_path)); //將背景圖拷貝到原圖上面 $src_image_1 = imagecreatefromstring(file_get_contents('./550x110.png')); //獲取圖片的寬高 $src_image_width_1 = imagesx($src_image_1); //寬 $src_imageheight_1 = imagesy($src_image_1); //高 $src_image_2 = imagecreatefromstring(file_get_contents('./550x430.png')); //獲取圖片的寬高 $src_image_width_2 = imagesx($src_image_2); //寬 $src_imageheight_2 = imagesy($src_image_2); //高 /** * imagecopy 參數注釋 * $dst 需要處理的原始圖片資源 * $src_image_1 需要復制到圖片上了另一資源圖片 * 100 420 原始圖片的x坐標開始復制 原始圖片的y坐標開始復制 * 從0,0 目標圖片的x,y坐標開始復制 到 src_image_width_1 src_imageheight_1 坐標結束 */ imagecopy($dst, $src_image_1, 100, 420, 0, 0, $src_image_width_1, $src_imageheight_1); imagecopy($dst, $src_image_2, 100, 540, 0, 0, $src_image_width_2, $src_imageheight_2); /*imagecreatefromstring()--從字符串中的圖像流新建一個圖像,返回一個圖像標示符,其表達了從給定字符串得來的圖像 圖像格式將自動監測,只要php支持jpeg,png,gif,wbmp,gd2.*/ $font = './3.ttf'; $black = imagecolorallocate($dst, 255, 255, 255); imagefttext($dst, 60, 0, 170, 510, $black, $font, 'Angle Badud'); imagefttext($dst, 370, 0, 140, 950, $black, $font, '01'); /* imagefttext($img,$size,$angle,$x,$y,$color,$fontfile,$text) $img由圖像創建函數返回的圖像資源 size要使用的水印的字體大小 angle(角度)文字的傾斜角度,如果是0度代表文字從左往右,如果是90度代表從上往下 x,y水印文字的第一個文字的起始位置 color是水印文字的顏色 fontfile,你希望使用truetype字體的路徑 http://www.manongjc.com/article/1302.html */ list($dst_w,$dst_h,$dst_type) = getimagesize($dst_path); /*list(mixed $varname[,mixed $......])--把數組中的值賦給一些變量 像array()一樣,這不是真正的函數,而是語言結構,List()用一步操作給一組變量進行賦值*/ /*getimagesize()能獲取到什么信息? getimagesize函數會返回圖像的所有信息,包括大小,類型等等*/ switch($dst_type){ case 1://GIF header("content-type:image/gif"); imagegif($dst); // imagegif($dst,'11.gif'); break; case 2://JPG header("content-type:image/jpeg"); imagejpeg($dst); // imagejpeg($dst,'11.jpg'); break; case 3://PNG header("content-type:image/png"); imagepng($dst); // imagepng($dst,'11.png'); break; default: break; /*imagepng--以PNG格式將圖像輸出到瀏覽器或文件 imagepng()將GD圖像流(image)以png格式輸出到標注輸出(通常為瀏覽器),或者如果用filename給出了文件名則將其輸出到文件*/ } imagedestroy($dst); ?>