-
//2.操作圖片 //2.1設(shè)置字體的路徑 $font = "msyh.ttf"; //2.2填寫我們的水印內(nèi)容 $content = "萌物語moe__1010"; //2.3設(shè)置字體的顏色RGB和透明度:參數(shù)1(內(nèi)存中的圖片),參數(shù)2(顏色) $col = imagecolorallocatealpha($image, 255, 255, 255, 50); //2.4寫入文字 imagettftext($image, 20, 0, 20, 30, $col, $font, $content);查看全部
-
//GD庫(kù):給圖片添加文字水印 //1.打開圖片 //1.1配置圖片路徑(就是你想要操作的圖片的路徑) $src = "yellow.jpg"; //1.2獲取圖片信息(通過GD庫(kù)提供的方法,得到你想要處理的圖片的基本信息) $info = getimagesize($src);//把圖片的基本信息賦值給$info變量。 /*echo "<pre>";//能讓打印效果更好看 print_r($info);*/ //1.3通過圖像的編號(hào)來獲取圖像的類型 $type = image_type_to_extension($info[2],false);//不需要.加一個(gè)false參數(shù) //print_r($type);//打印結(jié)果為jpeg //1.4在內(nèi)存中創(chuàng)建一個(gè)和我們圖像類型一樣的圖像 $fun = "imagecreatefrom{$type}"; //1.5把圖片復(fù)制到我們的內(nèi)存中 $image = $fun($src);查看全部
-
素材準(zhǔn)備: 1.原圖片不要用中文命名。 2.使用小圖作為水印。(PNG格式最佳) 3.字體庫(kù),windows有自帶的字體庫(kù)。(微軟雅黑) 4.開啟GD庫(kù):Wamp->打開php.ini->查找gd2->把extension=php_gd2.dll前面的;去掉。保存文件。查看全部
-
使用PHP中自帶的GD庫(kù)去處理圖片。 1.在網(wǎng)站上傳圖片的時(shí)候,自動(dòng)給圖片添加水印。 2.壓縮圖片,加快上傳速度。查看全部
-
圖片水印 打開圖片查看全部
-
文字水印 保存圖片 銷毀圖片查看全部
-
文字水印 操作圖片查看全部
-
文字水印 打開圖片查看全部
-
GD2圖片處理基本操作步驟: 1.打開圖片,加載圖片到內(nèi)存 2.操作圖片 3.輸出圖片 4.銷毀圖片查看全部
-
<?php //open picture $src = "001.jpg"; //get picture info $info = getimagesize($src); //get pirture type for num $type = image_type_to_extension($info[2],false); //build picture in stronge $fun = "imagecreatefrom{$type}"; //copy $image = $fun($src);//as imagecreatefromjpeg($src); //option picture //create width height px pricture $image_thumb = imagecreatetruecolor(200, 150); //copy after pirture in px priture imagecopyresampled($image_thumb,$image,0,0,0,0,200,150,$info[0],$info[1]); //destroy image imagedestroy($image); //show picture in borwer // ob_clean(); $funs = "image{$type}"; header("Content-type:".$info['mime']); $funs($image_thumb); // $funs($image_thumb,"thumb.".$type); //destroy imagedestroy($image_thumb); ?>查看全部
-
代碼段查看全部
-
代碼段查看全部
-
水印圖的完善版,可以完美生成透明水印 /** * 操作圖片(圖片水印) * string $image_Mark 水印地址 * int $x x軸位置 * int $y y軸位置 * int $pct 合并程度 100為完全合并,無透明 */ public function imageMark ($image_Mark,$x=0,$y=0,$pct=100) { $info2=getimagesize($image_Mark); $width=$info2[0];//水印寬 $height=$info2[1];//水印高 $type=image_type_to_extension($info2[2],false); $fun="imagecreatefrom{$type}"; $water=$fun($image_Mark);//創(chuàng)建水印圖 if($pct==100){ imagecopy($this->image,$water,$x,$y,0,0,$width,$height);//無透明 }else{ //1.生成真彩圖 $img = imagecreatetruecolor($width,$height); //2.把原圖畫入畫板 imagecopy($img,$this->image,0,0,$x,$y, $x+$width, $y+$height); //3.在畫板中加入水印 imagecopy($img,$water,0,0,0,0,$width,$height); //4.把畫板中的畫改變透明度后畫入原圖,使得水印有了透明效果 imagecopymerge($this->image,$img,$x,$y,0,0, $width, $height,$pct); imagedestroy($img); } imagedestroy($water);//釋放水印圖內(nèi)存 }查看全部
-
//保存圖片 public function save($path){ $funs="image{$this->info['type']}"; $funs($this->image,$path.".".$this->info['type']); } //文字水印 public function fontMark($content,$url,$size,$color,$local,$angle){ $color=imagecolorallocatealpha($this->image,$color[0],$color[1],$color[2],$color[3]); imagettftext($this->image,$size,$angle,$local['x'],$local['y'],$color,$url,$content); } //圖片水印 public function imageMark($source,$local,$alpha){ $info2=getimagesize($source); $type2=image_type_to_extension($info2[2],false); $func2="imagecreatefrom{$type2}"; $water=$func2($source); imagecopymerge($this->image,$water,$local['x'],$local['y'],0,0,$info2[0],$info2[1],$alpha); imagedestroy($water); } //銷毀圖片 public function __destruct(){ imagedestroy($this->image); }查看全部
-
<?php class Image{ public $info; private $image; //構(gòu)造函數(shù),打開文檔 public function __construct($src){ $info=getimagesize($src); $this->info=array( 'width'=>$info[0], 'height'=>$info[1], 'type'=>image_type_to_extension($info[2],false), 'mime'=>$info['mime'] ); $fun="imagecreatefrom{$this->info['type']}"; $this->image=$fun($src); } //壓縮圖片 public function thumb($width,$height){ $image_thumb=imagecreatetruecolor($width,$height); imagecopyresampled($image_thumb,$this->image,0,0,0,0,$width,$height,$this->info['width'],$this->info['height']); imagedestroy($this->image); $this->image=$image_thumb; } //顯示 圖片 public function show(){ header("Content-type:".$this->info['mime']); $funs="image{$this->info['type']}"; $funs($this->image); } } ?>查看全部
舉報(bào)
0/150
提交
取消