php上传图片加水印(图片水印,文字水印)
php上传图片加水印(图片水印,文字水印) 这是一款比较完整理的在用户上传图片时就自动给图片增加上水印,这款增加水印功能可以增加文字水印与图片水印哦。
php教程上传图片加水印(图片水印,文字水印)
这是一款比较完整理的在用户上传图片时就自动给图片增加上水印,这款增加水印功能可以增加文字水印与图片水印哦。
/*
* created on 2010-6-21
*
* the class for control image
*
* made by s71ence
*
* @$img_path 图片路径
* @$is_auto_reduce 图片是否自动按照大小等级压缩 1是
* @$is_appoint 是否手动进行压缩或放大 1是
* @$multiple 手动指定压缩/放大比例
* @$is_water_str 是否加水印文字 1是
* @$water_str 水印文字
* @$is_watermark 是否加水印图片 1是
* @$logo_path 水印图片路径
* @$is_display 是否显示图片 1是
* @$is_create 是否生成压缩后的图片 1是
*
* 注:
* 1.生成新图时不可显示图片,即$isdisplay和$iscreate不可同时置为1
* 2.当图片宽或高小于1000时,需手动设置压缩比例进行压缩
* 3.不建议启用水印,若要启用,建议原图片大小最好在1000以内
* 4.水印文字中不可含有中文
* 5.新生成的图片在原目录文件中,支持n个层级
*/class image_control
{
private $img_path;
private $is_auto_reduce;
private $is_appoint;
private $multiple;
private $is_water_str;
private $water_str;
private $is_watermark;
private $logo_path;
private $is_display;
private $is_create;function __construct($img_path,$is_auto_reduce,$is_appoint,$multiple,$is_water_str,$water_str,$is_watermark,$logo_path,$is_display,$is_create)
{
$this->img_path=$img_path;
$this->is_auto_reduce=$is_auto_reduce;
$this->is_appoint=$is_appoint;
$this->multiple=$multiple;
$this->is_water_str=$is_water_str;
$this->water_str=$water_str;
$this->is_watermark=$is_watermark;
$this->logo_path=$logo_path;
$this->is_display=$is_display;
$this->is_create=$is_create;
}function img_control()
{
//获取原图
$img_info=getimagesize($this->img_path);switch($img_info[2])
{
case 1:
$img_get=@imagecreatefromgif($this->img_path);
break;case 2:
$img_get=@imagecreatefromjpeg($this->img_path);
break;case 3:
$img_get=@imagecreatefrompng($this->img_path);
break;
}//文字水印
if($this->is_water_str==1)
{
//imagettftext(原图,文字大小,文字旋转,水印起始坐标x,水印起始坐标y,$te,'simhei.ttf',$str);
$te=imagecolorallocate($img_get,255,255,255);
$str=iconv("gbk","utf-8",$this->water_str);//水印文字
imagettftext($img_get,16,0,$img_info[0]-200,$img_info[1]-20,$te,'msyh.ttf',$str);
}//图片水印
if($this->is_watermark==1)
{
//水印图片处理
$logo_info=getimagesize($this->logo_path);switch($logo_info[2])
{
case 1:
$logo=@imagecreatefromgif($this->logo_path);
break;case 2:
$logo=@imagecreatefromjpeg($this->logo_path);
break;case 3:
$logo=@imagecreatefrompng($this->logo_path);
break;
}//水印logo图片
//函数说明:imagecopy(原图,水印图片,水印坐标x,水印坐标y,水印图片开始坐标x,水印图片开始坐标y,'水印图片宽','水印图片高');
imagecopy($img_get,$logo,0,0,0,0,$logo_info[0],$logo_info[1]);
}//自动图片压缩 按图片大小分级自动压缩
//imagecopyresized(画布,原图,画布起始x坐标,画布起始y坐标,原图起始x坐标,原图起始x坐标,新图片宽,新图片高,原图片宽,原图片高);
if($this->is_auto_reduce==1)
{
if($img_info[0]>=3000 || $img_info[1]>=3000)
{
$new_image_get=imagecreatetruecolor($img_info[0]*0.03,$img_info[1]*0.03);//生成画布
imagecopyresized($new_image_get,$img_get,0,0,0,0,$img_info[0]*0.03,$img_info[1]*0.03,$img_info[0],$img_info[1]);
}
else if($img_info[0]>=2500 || $img_info[1]>=2500)
{
$new_image_get=imagecreatetruecolor($img_info[0]*0.04,$img_info[1]*0.04);
imagecopyresized($new_image_get,$img_get,0,0,0,0,$img_info[0]*0.04,$img_info[1]*0.04,$img_info[0],$img_info[1]);
}
else if($img_info[0]>=2000 || $img_info[1]>=2000)
{
$new_image_get=imagecreatetruecolor($img_info[0]*0.05,$img_info[1]*0.05);
imagecopyresized($new_image_get,$img_get,0,0,0,0,$img_info[0]*0.05,$img_info[1]*0.05,$img_info[0],$img_info[1]);
}
else if($img_info[0]>=1500 || $img_info[1]>=1500)
{
$new_image_get=imagecreatetruecolor($img_info[0]*0.08,$img_info[1]*0.08);
imagecopyresized($new_image_get,$img_get,0,0,0,0,$img_info[0]*0.08,$img_info[1]*0.08,$img_info[0],$img_info[1]);
}
else if($img_info[0]>=1000 || $img_info[1]>=1000)
{
$new_image_get=imagecreatetruecolor($img_info[0]*0.1,$img_info[1]*0.1);
imagecopyresized($new_image_get,$img_get,0,0,0,0,$img_info[0]*0.1,$img_info[1]*0.1,$img_info[0],$img_info[1]);
}
else if($img_info[0]>=500 || $img_info[1]>=500)
{
$new_image_get=imagecreatetruecolor($img_info[0]*0.2,$img_info[1]*0.2);
imagecopyresized($new_image_get,$img_get,0,0,0,0,$img_info[0]*0.2,$img_info[1]*0.2,$img_info[0],$img_info[1]);
}
else if($img_info[0]>=300 || $img_info[1]>=300)
{
$new_image_get=imagecreatetruecolor($img_info[0]*0.3,$img_info[1]*0.3);
imagecopyresized($new_image_get,$img_get,0,0,0,0,$img_info[0]*0.3,$img_info[1]*0.3,$img_info[0],$img_info[1]);
}
else
{
$new_image_get=imagecreatetruecolor($img_info[0]*1,$img_info[1]*1);
imagecopyresized($new_image_get,$img_get,0,0,0,0,$img_info[0]*1,$img_info[1]*1,$img_info[0],$img_info[1]);
}
}//手动图片压缩
//imagecopyresized(画布,原图,画布起始x坐标,画布起始y坐标,原图起始x坐标,原图起始x坐标,新图片宽,新图片高,原图片宽,原图片高);
if($this->is_appoint)
{
$new_image_get=imagecreatetruecolor($img_info[0]*$this->multiple,$img_info[1]*$this->multiple);//生成画布
imagecopyresized($new_image_get,$img_get,0,0,0,0,$img_info[0]*$this->multiple,$img_info[1]*$this->multiple,$img_info[0],$img_info[1]);
}//图像输出
if($this->is_display==1)
{
header("content-type: image/jpeg");
return imagejpeg($new_image_get);
}//新图像生成
if($this->is_create==1)
{
$new_name=explode("/",$this->img_path);
$new_name_string="";for($i=0;$i
{
$new_name_string.=$new_name[$i]."/";
}$new_img_path=$new_name_string."new".$new_name[$i];
if(imagejpeg($new_image_get,$new_img_path) && imagejpeg($img_get,$this->img_path))
{
setcookie("img_new_path", $new_img_path);
//return "图片生成成功!
新图:".$new_img_path."
原图:".$this->img_path;
}
else
{
return "图片生成失败,请检查配置是否正确!";
}
}
}function __desctruct()
{
//clear
}
}
//调用方法
/* $img_path="../users/user_photo/t2.jpg"; //被操作的图片路径
$is_auto_reduce=1;//图片是否自动按照大小等级压缩 1是
$is_appoint=0;//是否手动进行压缩 1是
$multiple=0.5;//手动指定压缩比例
$is_water_str=0;//是否加水印文字
$water_str="www.bKjia.c0m";//水印文字
$is_watermark=0;//是否加水印图片 1是
$logo_path="../image/logo_about.gif";//水印图片路径
$is_display=0;//是否显示图片 1是
$is_create=1;//是否生成压缩后的图片 1是
$img=new image_control($img_path,$is_auto_reduce,$is_appoint,$multiple,$is_water_str,$water_str,$is_watermark,$logo_path,$is_display,$is_create);
echo $img->img_control();*/

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

PHP和Python各有優勢,選擇依據項目需求。 1.PHP適合web開發,尤其快速開發和維護網站。 2.Python適用於數據科學、機器學習和人工智能,語法簡潔,適合初學者。

PHP在電子商務、內容管理系統和API開發中廣泛應用。 1)電子商務:用於購物車功能和支付處理。 2)內容管理系統:用於動態內容生成和用戶管理。 3)API開發:用於RESTfulAPI開發和API安全性。通過性能優化和最佳實踐,PHP應用的效率和可維護性得以提升。

PHP是一種廣泛應用於服務器端的腳本語言,特別適合web開發。 1.PHP可以嵌入HTML,處理HTTP請求和響應,支持多種數據庫。 2.PHP用於生成動態網頁內容,處理表單數據,訪問數據庫等,具有強大的社區支持和開源資源。 3.PHP是解釋型語言,執行過程包括詞法分析、語法分析、編譯和執行。 4.PHP可以與MySQL結合用於用戶註冊系統等高級應用。 5.調試PHP時,可使用error_reporting()和var_dump()等函數。 6.優化PHP代碼可通過緩存機制、優化數據庫查詢和使用內置函數。 7

PHP仍然具有活力,其在現代編程領域中依然佔據重要地位。 1)PHP的簡單易學和強大社區支持使其在Web開發中廣泛應用;2)其靈活性和穩定性使其在處理Web表單、數據庫操作和文件處理等方面表現出色;3)PHP不斷進化和優化,適用於初學者和經驗豐富的開發者。

PHP和Python各有優勢,選擇應基於項目需求。 1.PHP適合web開發,語法簡單,執行效率高。 2.Python適用於數據科學和機器學習,語法簡潔,庫豐富。

PHP和Python各有優劣,選擇取決於項目需求和個人偏好。 1.PHP適合快速開發和維護大型Web應用。 2.Python在數據科學和機器學習領域佔據主導地位。

PHP適合web開發,特別是在快速開發和處理動態內容方面表現出色,但不擅長數據科學和企業級應用。與Python相比,PHP在web開發中更具優勢,但在數據科學領域不如Python;與Java相比,PHP在企業級應用中表現較差,但在web開發中更靈活;與JavaScript相比,PHP在後端開發中更簡潔,但在前端開發中不如JavaScript。

PHP主要是過程式編程,但也支持面向對象編程(OOP);Python支持多種範式,包括OOP、函數式和過程式編程。 PHP適合web開發,Python適用於多種應用,如數據分析和機器學習。
