欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP的圖像處理實例小結(jié)【文字水印、圖片水印、壓縮圖像等】

 更新時間:2019年12月20日 09:58:25   作者:theVicTory  
這篇文章主要介紹了PHP的圖像處理,結(jié)合實例形式總結(jié)分析了PHP針對文字水印、圖片水印、壓縮圖像等相關(guān)操作實現(xiàn)技巧,需要的朋友可以參考下

本文實例講述了PHP的圖像處理。分享給大家供大家參考,具體如下:

1、添加文字水印

//1、打開圖片資源
  $src="./material/sea.jpg";
  $info=getimagesize($src);//獲取圖片信息
  $type=image_type_to_extension($info[2],false);//轉(zhuǎn)化圖片類型
  //var_dump($info);
  $fun="imagecreatefrom{$type}";//拼接成為imagecreatefromjpeg()方法
  $image=$fun($src);//新建GD圖片資源
//操作圖片
  $font="./material/segoepr.ttf";
  $content="@SuperTory";
  $color=imagecolorallocate($image,255,255,255);
  imagettftext($image,10,0,0,$info[1]-5,$color,$font,$content);//圖片上寫文字
//輸出圖片
  header("content-type:".$info['mime']);//$imfo['mine']='image/jpeg'
  $output="image{$type}";//拼接成為imagejpeg()方法
  $output($image);//輸出到頁面
  $output($image,'./material/watermarked.'.$type);//輸出到本地路徑
//銷毀圖片內(nèi)存資源
  imagedestroy($image);

2、壓縮圖像

//打開圖像
$src="./material/logo.png";
$info=getimagesize($src);
$type=image_type_to_extension($info[2],false);
$create="imagecreatefrom".$type;
$image=$create($src);
//壓縮
$tinyImg=imagecreatetruecolor(100,100); //新建壓縮后的圖像資源
//將原圖映射到壓縮后的圖像資源上
imagecopyresampled($tinyImg,$image,0,0,0,0,100,100,$info[0],$info[1]);
header("content-type:".$info['mime']);
$output="image{$type}";
//$output($image);
$output($tinyImg);
//銷毀
imagedestroy($image);
imagedestroy($tinyImg);

3、添加水印圖片

//獲取原圖片
$src="./material/sea.jpg";
$info=getimagesize($src);
$type=image_type_to_extension($info[2],false);
$create="imagecreatefrom".$type;
$image=$create($src);
//獲取水印圖片資源
$markSrc="./material/logo.png";
$markInfo=getimagesize($markSrc);
$markType=image_type_to_extension($markInfo[2],false);
$create="imagecreatefrom".$markType;
$markImage=$create($markSrc);
$tinyImg=imagecreatetruecolor(100,100);
imagecopyresampled($tinyImg,$markImage,0,0,0,0,
  100,100,$markInfo[0],$markInfo[1]);
imagecopymerge($image,$tinyImg,$info[0]-100,$info[1]-100,
  0,0,100,100,100);
//合并圖片:(原圖,水印圖,原圖x位置,原圖y位置,水印x起點,水印y起點,水印x終點,水印y終點,不透明度)
header("content-type:".$info['mime']);
$output="image{$type}";
$output($image);
imagedestroy($image);
imagedestroy($markImage);

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP圖形與圖片操作技巧匯總》、《PHP數(shù)組(Array)操作技巧大全》、《PHP數(shù)據(jù)結(jié)構(gòu)與算法教程》、《php程序設(shè)計算法總結(jié)》、《PHP數(shù)學(xué)運算技巧總結(jié)》、《php字符串(string)用法總結(jié)》及《php常見數(shù)據(jù)庫操作技巧匯總

希望本文所述對大家PHP程序設(shè)計有所幫助。

相關(guān)文章

最新評論