### 圖片+水印文字
~~~
<?php
/**
* 圖片水印
* Created by PhpStorm.
* User: Administrator
* Date: 2017/1/14 0014
* Time: 下午 2:27
*/
class ImageWater
{
/**
處理完成保存到原路徑
* @param $filename 圖片的路徑
* @param string $waterstring 水印文字
*/
public function waterText($filename, $waterstring = 'hello world')
{
$imgquality = 100; //圖片質量0-100,值最大圖片質量愈好,圖片的大小也越大 *推薦90-100 太小圖片會出現模糊現象
$image_size = getimagesize($filename);
$upimgw = $image_size[0]; //上傳圖片的寬度
$upimgh = $image_size[1]; //上傳圖片的高度
$iinfo = getimagesize($filename);
$nimage = imagecreatetruecolor($image_size[0], $image_size[1]);
$white = imagecolorallocate($nimage, 118, 196, 234);
imagefill($nimage, 0, 0, $white);
switch ($iinfo[2]) {
case 1:
$simage = imagecreatefromgif($filename);
break;
case 2:
$simage = imagecreatefromjpeg($filename);
break;
case 3:
$simage = imagecreatefrompng($filename);
break;
case 6:
$simage = imagecreatefromwbmp($filename);
break;
default:
die("不支持的文件類型");
exit;
}
imagecopy($nimage, $simage, 0, 0, 0, 0, $image_size[0], $image_size[1]);
$waterstart_x = $upimgw / 2 - 50;
//echo $upimgh;
$waterstart_y = $upimgh - 20;
imagestring($nimage, 6, $waterstart_x, $waterstart_y, $waterstring, $white);
//int imagestring(int im, int font, int x, int y, string s, int col);返回值: 整數 函數種類: 圖形處理b 內容說明:本函數在圖片上繪出水平的橫式字符串。參數 font 為字形,設為 1 到 5 表示使用默認字形。參數 x、y 為字符串起點坐標。字符串的內容放在參數 s 上。參數 col 表示字符串的顏色。
switch ($iinfo[2]) {
case 1:
//imagegif($nimage, $destination);
imagejpeg($nimage, $filename, $imgquality);
break;
case 2:
imagejpeg($nimage, $filename, $imgquality);
break;
case 3:
imagepng($nimage, $filename, $imgquality);
break;
case 6:
imagewbmp($nimage, $filename, $imgquality);
//imagejpeg($nimage, $destination);
break;
}
//覆蓋原上傳文件
imagedestroy($nimage);
imagedestroy($simage);
}
}
~~~
#### 調用案例
~~~
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2017/1/14 0014
* Time: 下午 2:41
*/
require_once 'ImageWater.php';
$imageWater=new ImageWater();
$filename='00107.jpg';
echo "<img src='".$filename."'/>";
$imageWater->waterText($filename,'hdghagd');
echo "<img src='".$filename."'/>";
~~~
- 我的筆記
- 服務器
- ubuntu svn 環境的搭建
- ubuntu Memcache 的配置
- ubuntu 密鑰登錄服務器
- centos 搭建服務器環境
- nginx+tomcat 集群搭建
- 餐廳運營來看如何構建高性能服務器
- VMware-Centos-網絡配置
- Ubuntu-PHP-Apache-Mysql-PhpMyadmin的搭建
- UbuntuApache配置日志
- linux獲取當前執行腳本的目錄
- Ubuntu svn的快速配置(原創)
- Https配置
- Mysql 不支持遠程連接解決方案
- ubuntu+apache+rewrite
- php Mcrypt 擴展
- 重啟Apache出現警告信息Could not reliably determine the server's fully qualified domain name,
- Mysql無法遠程連接
- 定時任務設置
- Linux中Cache內存占用過高解決辦法
- Ubuntu14-04安裝redis和php5-redis擴展
- php
- thinkphp3.2 一站多城市配置
- PHP 安全編程建議(轉)
- phpexcel導入時間處理
- Mysql按時,天,月,年統計數據
- PHP-支付寶-APP支付
- 百度爬蟲-獲取全國數據
- PHPEXCEL導入導出excel文件
- php-微信app支付后端設計
- Phpqrcode生成二維碼
- 圖片+文字水印
- 數據庫優化
- java
- Mybatis 二級緩存
- 微信
- 微信公眾號多域名授權
- 微信掃碼支付
- web
- 網站性能優化方案實施
- ionic環境搭建
- 登錄設計方案
- 設置dev元素的寬高比例
- 設計模式
- app
- 版本更新
- 微擎數據庫操作擴展
- select
- find
- delete
- update
- insert
- where
- order
- page
- group
- having
- limit
- fields
- debug
- bind
- join
- alias
- query
- 聚合函數
- count
- sum
- max
- min
- avg
- 事務管理
- 自增自減
- 算法設計
- ACM:入口的選擇------深度優先搜索
- java:N的N次方
- 最少攔截系統:貪心思想
- ACM:蠶寶寶:搜索
- ACM:n!的位數 :斯特林公式
- 神奇的異或
- 中國剩余定理
- 矩陣翻硬幣
- 回溯法
- ACM程序設計網站集錦
- 博弈論
- 多維空間上的搜索算法
- 算法學習筆記之一(排序)
- 算法學習筆記之二(堆排序)
- 算法學習筆記之三(快速排序)
- ACM俱樂部密碼
- 原創開源
- 個人感悟