nginx configuration proxy
location ~ /image/.*\.(gif|jpg|jpeg|png)$ { proxy_pass http://127.0.0.1:8888/test/watermark?url=$request_uri; }
/img/
matches the directory prefix to be proxied, $request_uri
parameter is accessed Image path.
php watermark class
/** 水印类 * Class Watermark * @package app\test */ class Watermark { /** 合成图片水印 * @param string $dstImage 原图片 * @param string $waterImg 水印图 */ public static function imageMarking($dstImage, $waterImg){ //获取图片信息 $dstInfo = getimagesize($dstImage); $waterInfo = getimagesize($waterImg); //创建图像 $dstImgObj = self::imageCreateFrom($dstImage, $dstInfo[2]); $waterImgObj = self::imageCreateFrom($waterImg, $waterInfo[2]); //合成水印 imagecopyresized($dstImgObj,$waterImgObj,0, 0,0,0,$dstInfo[0], $dstInfo[1],$waterInfo[0],$waterInfo[1]); //输出图片 self::imageOut($dstImgObj,$waterInfo[2]); //销毁资源对象 imagedestroy($dstImgObj); imagedestroy($waterImgObj); } /** 生成图片对象 * @param string $imgFile 图片路径 * @param string $type 图片类型 * @return false|\GdImage|resource */ private static function imageCreateFrom($imgFile, $type) { switch ($type) { case IMAGETYPE_GIF: return imagecreatefromgif($imgFile); case IMAGETYPE_JPEG: return imagecreatefromjpeg($imgFile); case IMAGETYPE_PNG: return imagecreatefrompng($imgFile); default : //其他格式 } } /** 输出图片 * @param string $imageObj * @param string $type */ private static function imageOut($imageObj,$type){ switch ($type) { case 1: header("Content-Type: image/gif"); imagegif($imageObj); break; case 2: header("Content-Type: image/jpeg"); imagejpeg($imageObj); break; case 3: header("Content-Type: image/png"); imagepng($imageObj); break; default: //其他格式 } } }
Call example
public function watermark(){ //图片路径前缀 $image = '/data/img/' . input('url'); self::imageMarking($image,'watermark.png'); exit; }
The above is the detailed content of How nginx adds watermark to images through PHP proxy. For more information, please follow other related articles on the PHP Chinese website!

NGINX and Apache each have their own advantages and disadvantages, and the choice should be based on specific needs. 1.NGINX is suitable for high concurrency scenarios because of its asynchronous non-blocking architecture. 2. Apache is suitable for low-concurrency scenarios that require complex configurations, because of its modular design.

NGINXUnit is an open source application server that supports multiple programming languages and provides functions such as dynamic configuration, zero downtime updates and built-in load balancing. 1. Dynamic configuration: You can modify the configuration without restarting. 2. Multilingual support: compatible with Python, Go, Java, PHP, etc. 3. Zero downtime update: Supports application updates that do not interrupt services. 4. Built-in load balancing: Requests can be distributed to multiple application instances.

NGINXUnit is better than ApacheTomcat, Gunicorn and Node.js built-in HTTP servers, suitable for multilingual projects and dynamic configuration requirements. 1) Supports multiple programming languages, 2) Provides dynamic configuration reloading, 3) Built-in load balancing function, suitable for projects that require high scalability and reliability.

NGINXUnit improves application performance and manageability with its modular architecture and dynamic reconfiguration capabilities. 1) Modular design includes master processes, routers and application processes, supporting efficient management and expansion. 2) Dynamic reconfiguration allows seamless update of configuration at runtime, suitable for CI/CD environments. 3) Multilingual support is implemented through dynamic loading of language runtime, improving development flexibility. 4) High performance is achieved through event-driven models and asynchronous I/O, and remains efficient even under high concurrency. 5) Security is improved by isolating application processes and reducing the mutual influence between applications.

NGINXUnit can be used to deploy and manage applications in multiple languages. 1) Install NGINXUnit. 2) Configure it to run different types of applications such as Python and PHP. 3) Use its dynamic configuration function for application management. Through these steps, you can efficiently deploy and manage applications and improve project efficiency.

NGINX is more suitable for handling high concurrent connections, while Apache is more suitable for scenarios where complex configurations and module extensions are required. 1.NGINX is known for its high performance and low resource consumption, and is suitable for high concurrency. 2.Apache is known for its stability and rich module extensions, which are suitable for complex configuration needs.

NGINXUnit improves application flexibility and performance with its dynamic configuration and high-performance architecture. 1. Dynamic configuration allows the application configuration to be adjusted without restarting the server. 2. High performance is reflected in event-driven and non-blocking architectures and multi-process models, and can efficiently handle concurrent connections and utilize multi-core CPUs.

NGINX and Apache are both powerful web servers, each with unique advantages and disadvantages in terms of performance, scalability and efficiency. 1) NGINX performs well when handling static content and reverse proxying, suitable for high concurrency scenarios. 2) Apache performs better when processing dynamic content and is suitable for projects that require rich module support. The selection of a server should be decided based on project requirements and scenarios.


Hot AI Tools

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

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

Undress AI Tool
Undress images for free

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

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

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

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
