php上傳圖片加水印(圖片水印,文字水?。?/h1>
Jun 13, 2016 am 09:48 AM
php
upload
add
picture
picture
exist
tidy
letter
payment
Compare
watermark
user
of
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圖片
???//函數(shù)說明: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();*/

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The method to get the current session ID in PHP is to use the session_id() function, but you must call session_start() to successfully obtain it. 1. Call session_start() to start the session; 2. Use session_id() to read the session ID and output a string similar to abc123def456ghi789; 3. If the return is empty, check whether session_start() is missing, whether the user accesses for the first time, or whether the session is destroyed; 4. The session ID can be used for logging, security verification and cross-request communication, but security needs to be paid attention to. Make sure that the session is correctly enabled and the ID can be obtained successfully.

To extract substrings from PHP strings, you can use the substr() function, which is syntax substr(string$string,int$start,?int$length=null), and if the length is not specified, it will be intercepted to the end; when processing multi-byte characters such as Chinese, you should use the mb_substr() function to avoid garbled code; if you need to intercept the string according to a specific separator, you can use exploit() or combine strpos() and substr() to implement it, such as extracting file name extensions or domain names.

UnittestinginPHPinvolvesverifyingindividualcodeunitslikefunctionsormethodstocatchbugsearlyandensurereliablerefactoring.1)SetupPHPUnitviaComposer,createatestdirectory,andconfigureautoloadandphpunit.xml.2)Writetestcasesfollowingthearrange-act-assertpat

In PHP, the most common method is to split the string into an array using the exploit() function. This function divides the string into multiple parts through the specified delimiter and returns an array. The syntax is exploit(separator, string, limit), where separator is the separator, string is the original string, and limit is an optional parameter to control the maximum number of segments. For example $str="apple,banana,orange";$arr=explode(",",$str); The result is ["apple","bana

JavaScript data types are divided into primitive types and reference types. Primitive types include string, number, boolean, null, undefined, and symbol. The values are immutable and copies are copied when assigning values, so they do not affect each other; reference types such as objects, arrays and functions store memory addresses, and variables pointing to the same object will affect each other. Typeof and instanceof can be used to determine types, but pay attention to the historical issues of typeofnull. Understanding these two types of differences can help write more stable and reliable code.

std::chrono is used in C to process time, including obtaining the current time, measuring execution time, operation time point and duration, and formatting analysis time. 1. Use std::chrono::system_clock::now() to obtain the current time, which can be converted into a readable string, but the system clock may not be monotonous; 2. Use std::chrono::steady_clock to measure the execution time to ensure monotony, and convert it into milliseconds, seconds and other units through duration_cast; 3. Time point (time_point) and duration (duration) can be interoperable, but attention should be paid to unit compatibility and clock epoch (epoch)

In PHP, to pass a session variable to another page, the key is to start the session correctly and use the same $_SESSION key name. 1. Before using session variables for each page, it must be called session_start() and placed in the front of the script; 2. Set session variables such as $_SESSION['username']='JohnDoe' on the first page; 3. After calling session_start() on another page, access the variables through the same key name; 4. Make sure that session_start() is called on each page, avoid outputting content in advance, and check that the session storage path on the server is writable; 5. Use ses

ToaccessenvironmentvariablesinPHP,usegetenv()orthe$_ENVsuperglobal.1.getenv('VAR_NAME')retrievesaspecificvariable.2.$_ENV['VAR_NAME']accessesvariablesifvariables_orderinphp.iniincludes"E".SetvariablesviaCLIwithVAR=valuephpscript.php,inApach
