


PHP uploads pictures and adds watermarks (picture watermarks, text watermarks)_PHP tutorial
Jul 13, 2016 am 10:45 AMphp upload pictures and add watermarks (picture watermarks, text watermarks) This is a relatively complete software that automatically adds watermarks to pictures when users upload them. This watermark adding function can add text watermarks and picture watermarks.
php tutorial to upload pictures and add watermarks (picture watermarks, text watermarks)
This is a relatively complete software that automatically adds watermarks to pictures when users upload them. This watermark adding function can add text watermarks and picture watermarks.
/*
* created on 2010-6-21
*
* the class for control image
*
* made by s71ence
*
* @$img_path image path
* @$is_auto_reduce Whether the image is automatically compressed according to the size level 1 is
* @$is_appoint Whether to manually compress or amplify 1 Yes
* @$multiple Manually specify compression/amplification ratio
* @$is_water_str Whether to add watermark text 1 is
* @$water_str watermark text
* @$is_watermark Whether to add watermark to the picture 1 Yes
* @$logo_path Watermark image path
* @$is_display Whether to display pictures 1 is
* @$is_create Whether to generate compressed images 1 is
*
* Note:
* 1. Images cannot be displayed when generating new images, that is, $isdisplay and $iscreate cannot be set to 1 at the same time
* 2. When the image width or height is less than 1000, you need to manually set the compression ratio for compression
* 3. It is not recommended to enable watermarks. If you want to enable it, it is recommended that the original image size should be within 1000
* 4. The watermark text cannot contain Chinese
* 5. The newly generated image is in the original directory file and supports n levels
*/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()
{
//Get the original image
$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;
}//Text watermark
if($this->is_water_str==1)
{
//imagettftext(original image, text size, text rotation, watermark starting coordinate x, watermark starting coordinate y, $te,'simhei.ttf',$str);
$te=imagecolorallocate($img_get,255,255,255);
$str=iconv("gbk","utf-8",$this->water_str);//Watermark text
Imagettftext($img_get,16,0,$img_info[0]-200,$img_info[1]-20,$te,'msyh.ttf',$str);
}//Picture watermark
if($this->is_watermark==1)
{
//Watermark image processing
$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;
}//Watermark logo image
//Function description: imagecopy(original image, watermark image, watermark coordinate x, watermark coordinate y, watermark image start coordinate x, watermark image start coordinate y, 'watermark image width', 'watermark image height');
Imagecopy($img_get,$logo,0,0,0,0,$logo_info[0],$logo_info[1]);
}//Automatic image compression Automatic compression based on image size classification
//imagecopyresized(canvas, original image, canvas starting x coordinate, canvas starting y coordinate, original image starting x coordinate, original image starting x coordinate, new image width, new image height, original image width, original image height );
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);//Generate canvas
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]);
}
}//Manual image compression
//imagecopyresized(canvas, original image, canvas starting x coordinate, canvas starting y coordinate, original image starting x coordinate, original image starting x coordinate, new image width, new image height, original image width, original image height );
if($this->is_appoint)
{
$new_image_get=imagecreatetruecolor($img_info[0]*$this->multiple,$img_info[1]*$this->multiple);//Generate canvas
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]);
}//Image output
if($this->is_display==1)
{
Header("content-type: image/jpeg");
Return imagejpeg($new_image_get);
}//New image generation
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 "Image generated successfully!
New image: ".$new_img_path."
Original image: ".$this->img_path;
}
else
{
Return "The image generation failed, please check whether the configuration is correct!";
}
}
}function __desctruct()
{
//clear
}
}
//Call method
/* $img_path="../users/user_photo/t2.jpg"; //The path of the image being manipulated
$is_auto_reduce=1;//Whether the image is automatically compressed according to the size level 1 is
$is_appoint=0;//Whether to compress manually 1 is
$multiple=0.5;//Manually specify the compression ratio
$is_water_str=0;//Whether to add watermark text
$water_str="www.bKjia.c0m";//Watermark text
$is_watermark=0;//Whether to add watermark to the picture 1 is
$logo_path="../image/logo_about.gif";//Watermark image path
$is_display=0;//Whether to display the picture 1 is
$is_create=1;//Whether to generate compressed images 1 is
$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)

User voice input is captured and sent to the PHP backend through the MediaRecorder API of the front-end JavaScript; 2. PHP saves the audio as a temporary file and calls STTAPI (such as Google or Baidu voice recognition) to convert it into text; 3. PHP sends the text to an AI service (such as OpenAIGPT) to obtain intelligent reply; 4. PHP then calls TTSAPI (such as Baidu or Google voice synthesis) to convert the reply to a voice file; 5. PHP streams the voice file back to the front-end to play, completing interaction. The entire process is dominated by PHP to ensure seamless connection between all links.

The core method of building social sharing functions in PHP is to dynamically generate sharing links that meet the requirements of each platform. 1. First get the current page or specified URL and article information; 2. Use urlencode to encode the parameters; 3. Splice and generate sharing links according to the protocols of each platform; 4. Display links on the front end for users to click and share; 5. Dynamically generate OG tags on the page to optimize sharing content display; 6. Be sure to escape user input to prevent XSS attacks. This method does not require complex authentication, has low maintenance costs, and is suitable for most content sharing needs.

To realize text error correction and syntax optimization with AI, you need to follow the following steps: 1. Select a suitable AI model or API, such as Baidu, Tencent API or open source NLP library; 2. Call the API through PHP's curl or Guzzle and process the return results; 3. Display error correction information in the application and allow users to choose whether to adopt it; 4. Use php-l and PHP_CodeSniffer for syntax detection and code optimization; 5. Continuously collect feedback and update the model or rules to improve the effect. When choosing AIAPI, focus on evaluating accuracy, response speed, price and support for PHP. Code optimization should follow PSR specifications, use cache reasonably, avoid circular queries, review code regularly, and use X

1. Maximizing the commercial value of the comment system requires combining native advertising precise delivery, user paid value-added services (such as uploading pictures, top-up comments), influence incentive mechanism based on comment quality, and compliance anonymous data insight monetization; 2. The audit strategy should adopt a combination of pre-audit dynamic keyword filtering and user reporting mechanisms, supplemented by comment quality rating to achieve content hierarchical exposure; 3. Anti-brushing requires the construction of multi-layer defense: reCAPTCHAv3 sensorless verification, Honeypot honeypot field recognition robot, IP and timestamp frequency limit prevents watering, and content pattern recognition marks suspicious comments, and continuously iterate to deal with attacks.

PHP does not directly perform AI image processing, but integrates through APIs, because it is good at web development rather than computing-intensive tasks. API integration can achieve professional division of labor, reduce costs, and improve efficiency; 2. Integrating key technologies include using Guzzle or cURL to send HTTP requests, JSON data encoding and decoding, API key security authentication, asynchronous queue processing time-consuming tasks, robust error handling and retry mechanism, image storage and display; 3. Common challenges include API cost out of control, uncontrollable generation results, poor user experience, security risks and difficult data management. The response strategies are setting user quotas and caches, providing propt guidance and multi-picture selection, asynchronous notifications and progress prompts, key environment variable storage and content audit, and cloud storage.

PHP ensures inventory deduction atomicity through database transactions and FORUPDATE row locks to prevent high concurrent overselling; 2. Multi-platform inventory consistency depends on centralized management and event-driven synchronization, combining API/Webhook notifications and message queues to ensure reliable data transmission; 3. The alarm mechanism should set low inventory, zero/negative inventory, unsalable sales, replenishment cycles and abnormal fluctuations strategies in different scenarios, and select DingTalk, SMS or Email Responsible Persons according to the urgency, and the alarm information must be complete and clear to achieve business adaptation and rapid response.

PHPisstillrelevantinmodernenterpriseenvironments.1.ModernPHP(7.xand8.x)offersperformancegains,stricttyping,JITcompilation,andmodernsyntax,makingitsuitableforlarge-scaleapplications.2.PHPintegrateseffectivelyinhybridarchitectures,servingasanAPIgateway

The core role of Homebrew in the construction of Mac environment is to simplify software installation and management. 1. Homebrew automatically handles dependencies and encapsulates complex compilation and installation processes into simple commands; 2. Provides a unified software package ecosystem to ensure the standardization of software installation location and configuration; 3. Integrates service management functions, and can easily start and stop services through brewservices; 4. Convenient software upgrade and maintenance, and improves system security and functionality.
