-
$src="gd_01.jpeg"; $info=getimagesize($src); $type=image_type_to_extension($info[2],false); $fun="imagecreatefrom{$type}"; $image=$fun($type);查看全部
-
<?php /*打開圖片*/ $src='gd_01.jpeg'; $info=getimagesize($src); //echo '<pre>'; //print_r($info); /*$info Array ( [0] => 640 索引 0 包含圖像寬度的像素值 [1] => 856 索引 1 包含圖像高度的像素值 [2] => 2 索引 2 是圖像類型的標(biāo)記:1 = GIF,2 = JPG,3 = PNG, [3] => width="640" height="856" [bits] => 8 [channels] => 3 [mime] => image/jpeg ) */ $type=image_type_to_extension($info['2'],false); $fun="imagecreatefrom{$type}"; $image=$fun($src); /*操作圖片*/ $font='msyhbd.ttf'; $content='hello PHP'; $color=imagecolorallocatealpha($image, 255, 255, 255, 50);//設(shè)置字體顏色和透明度 imagettftext($image, 20, 0, 20, 30, $color, $font, $content); /*s輸出圖片*/ //瀏覽器輸出 header("content-type:".$info['mime']); $func="image{$type}"; $func($image); //保存圖片 $type01=image_type_to_extension($info['2']); $func($image,newimage.$type01); /*銷毀圖片*/ imagedestory();查看全部
-
打開圖片要進(jìn)行的操作: 1.配置要處理的圖片路徑 2.獲取圖片信息:getimagesize() 3.通過圖像編號(hào)來獲取圖片類型image_type_to_extension() 4.在內(nèi)存中創(chuàng)建一個(gè)和圖片類型一樣的圖片imagecreatefrom{$type}查看全部
-
<?php //打開圖片 $src="./images/001.jpg"; $info = getimagesize($src); $type = image_type_to_extension($info[2],false); $image= imagecreatefromjpeg($src); $font = "./images/AdobeKaitiStd-Regular.otf"; $content = "哈嘍"; $col=imagecolorallocatealpha($image,255,255,50); imagettftext($image,20,0,20,30,$col,$font,$content); header("Content-type:".$info['mime']); imagejpeg($image); imagejpeg($image,"newige.jpg"); //操作圖片 //輸出圖片 //銷毀圖片 ?>查看全部
-
image.class.php //封裝成類————添加圖片水印(操作圖片) public function imageMark($source,$local,$alpha){ $info2 = getimagesize($source); $type2 = image_type_to_extension($info2[2],false); $fun2 = "imagecreatefrom{$type2}"; $water = $fun2($source); imagecopymerge($this->image,$water,$local['x'],$local['y'],0,0,$info2[0],$info2[1],$alpha); imagedestroy($water); } test.php <?php require "image.class.php"; $src = "yellow.jpg"; //添加圖片水印 $source = 'weixin.png'; $local = array( 'x' => 20, 'y' => 50 ); $alpha = 30; $image = new Image($src); //$image->thumb(300,150);//壓縮圖片 //$image->fontMark($content,$font_url,$size,$color,$local,$angle);//文字水印 $image->imageMark($source,$local,$alpha);//圖片水印 $image->show(); //$image->save("fontMark");//保存文字水印圖片 ?>查看全部
-
image.class.php //封裝成類————添加文字水印(操作圖片) public function fontMark($content,$font_url,$size,$color,$local,$angle){ $col = imagecolorallocatealpha($this->image, $color[0], $color[1], $color[2], $color[3]); imagettftext($this->image, $size, $angle, $local['x'], $local['y'], $col, $font_url, $content); } test.php <?php require "image.class.php"; $src = "yellow.jpg"; $content = 'moe1010'; $font_url = 'msyh.ttf'; $size = 20; $color = array( 0 => 255, 1 => 255, 2 => 255, 3 => 20 ); $local = array( 'x' => 20, 'y' => 50 ); $angle = 10; $image = new Image($src); //$image->thumb(300,150); $image->fontMark($content,$font_url,$size,$color,$local,$angle); $image->show(); $image->save("fontMark"); ?>查看全部
-
test.php <?php require "image.class.php"; $src = "yellow.jpg"; $image = new Image($src); $image->thumb(300,150); $image->show(); ?>查看全部
-
//封裝成類-壓縮圖片 class Image{ private $image; private $info; //1.打開一張圖片,讀取到內(nèi)存中 public function __construct($src){ $info = getimagesize($src);//獲取圖片信息放在$info里 $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); } //2.操作圖片(壓縮) 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;} //3.在瀏覽器中輸出圖片 public function show(){ header("Content-type:".$this->info['mime']); $funs = "image{$this->info['type']}"; $funs($this->image);} //4.把圖片保存到硬盤里 public function save($newname){ $funs = "image{$this->info['type']}"; $funs($this->image,$newname.'.'.$this->info['type']);} //5.銷毀圖片 public function __destruct(){ imagedestroy($this->image);}}查看全部
-
//3.輸出圖片 //3.1把圖片輸出到瀏覽器 header("Content-type:".$info['mime']);//告訴瀏覽器輸出的內(nèi)容是圖片。mime:類型 $funs = "image{$type}";//這樣就能實(shí)現(xiàn)不同圖片調(diào)用不同函數(shù) $funs($image_thumb); //3.2保存圖片 $funs($image_thumb,'thumbyellow.'.$type); //4.銷毀圖片 imagedestroy($image_thumb);查看全部
-
//2.操作圖片 //2.1在內(nèi)存中建立一個(gè)寬300,高200的真色彩圖片 $image_thumb = imagecreatetruecolor(300,200); //2.2核心步驟:將原圖復(fù)制到新建的真色彩圖片上,并且按照一定比例壓縮 imagecopyresampled($image_thumb,$image,0,0,0,0,300,200,$info[0],$info[1]); //3.銷毀原始圖片 imagedestroy($image);查看全部
-
//GD庫:生成圖片縮略圖 //1.打開圖片 //1.1配置圖片路徑(就是你想要操作的圖片的路徑) $src = "yellow.jpg"; //1.2獲取圖片的基本信息(通過GD庫提供的方法,得到你想要處理的圖片的基本信息) $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);查看全部
-
//3.輸出圖片 //3.1瀏覽器輸出 //ob_clean();//清空(擦掉)輸出緩沖區(qū) header("Content-type:".$info['mime']);//告訴瀏覽器輸出的內(nèi)容是圖片。mime:類型 $funs = "image{$type}";//這樣就能實(shí)現(xiàn)不同圖片調(diào)用不同函數(shù) $funs($image); //3.2保存圖片 $funs($image,'wateryellow.'.$type); //4.銷毀圖片:清理掉內(nèi)存中的圖片副本,釋放內(nèi)存。 imagedestroy($image);查看全部
-
//2.操作圖片 //2.1設(shè)置水印路徑 $image_Mark = "weixin.png"; //2.2獲取水印圖片的基本信息 $info2 = getimagesize($image_Mark); //2.3通過水印的圖像編號(hào)來獲取水印的圖片類型 $type2 = image_type_to_extension($info2[2],false); //2.4在內(nèi)存中創(chuàng)建一個(gè)和我們水印圖像一致的圖像類型 $fun2 = "imagecreatefrom{$type2}"; //2.5把水印圖片復(fù)制到內(nèi)存中 $water = $fun2($image_Mark); //2.6合并圖片 imagecopymerge($image,$water,20,30,0,0,$info2[0],$info2[1],30); //2.7銷毀水印圖片 imagedestroy($water);查看全部
-
//GD庫:給圖片添加圖片水印 //1.打開圖片 //1.1配置圖片路徑(就是你想要操作的圖片的路徑) $src = "yellow.jpg"; //1.2獲取圖片的基本信息(通過GD庫提供的方法,得到你想要處理的圖片的基本信息) $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);查看全部
-
//3.輸出圖片 //3.1瀏覽器輸出 //ob_clean();//清空(擦掉)輸出緩沖區(qū) header("Content-type:".$info['mime']);//告訴瀏覽器輸出的內(nèi)容是圖片 $func = "image{$type}";//這樣就能實(shí)現(xiàn)不同圖片調(diào)用不同函數(shù) $func($image); //3.2保存圖片 $func($image,'newyellow.'.$type); //4.銷毀圖片:清理掉內(nèi)存中的圖片副本,釋放內(nèi)存。 imagedestroy($image);查看全部
舉報(bào)
0/150
提交
取消