Home Web Front-end HTML Tutorial Add watermark to images uploaded to Baidu UEDITOR editor_html/css_WEB-ITnose

Add watermark to images uploaded to Baidu UEDITOR editor_html/css_WEB-ITnose

Jun 24, 2016 am 11:46 AM


Add watermark to upload images to Baidu UEDITOR editor_html/css_WEB-ITnose

form: http://www.uphtm.com /php/255.html

The pictures uploaded by the UEDITOR editor are automatically extracted, but the pictures do not have a watermark function. The editor will take a look with you below.

UEditor editor does not have the function of uploading pictures and adding watermarks, and requires secondary development. This example is to perform secondary development of the Baidu editor in the PHPCMS system and add the function of uploading pictures and adding watermarks.


First open the php folder in the UEditor editor file directory, open Uploader.class.php, copy the PHPCMS method of adding watermarks, add it to the end of all member methods of this class, and then modify it As follows:

//图片加水印
public function watermark($source, $target = '', $w_pos = '', $w_img = '', $w_text = '99danji',$w_font = 8, 
$w_color = '#ff0000') {
    $this->w_img = 'watermark.png';
    $this->w_pos = 9;
    $this->w_minwidth = 400;
    $this->w_minheight = 200;
    $this->w_quality = 80;
    $this->w_pct = 85;
 
    $w_pos = $w_pos ? $w_pos : $this->w_pos;
    $w_img = $w_img ? $w_img : $this->w_img;
    //if(!$this->watermark_enable || !$this->check($source)) return false;
    if(!$target) $target = $source;
    //$w_img = PHPCMS_PATH.$w_img;
    //define('WWW_PATH', dirname(dirname(dirname(__FILE__)));
    $w_img = '../../../images/water/'.$w_img;
    $source_info = getimagesize($source);
    $source_w    = $source_info[0];
    $source_h    = $source_info[1];
    //if($source_w < $this->w_minwidth || $source_h < $this->w_minheight) return false;
    switch($source_info[2]) {
        case 1 :
            $source_img = imagecreatefromgif($source);
            break;
        case 2 :
            $source_img = imagecreatefromjpeg($source);
            break;
        case 3 :
            $source_img = imagecreatefrompng($source);
            break;
        default :
            return false;
    }
    if(!empty($w_img) && file_exists($w_img)) {
        $ifwaterimage = 1;
        $water_info   = getimagesize($w_img);
        $width        = $water_info[0];
        $height       = $water_info[1];
        switch($water_info[2]) {
            case 1 :
                $water_img = imagecreatefromgif($w_img);
                break;
            case 2 :
                $water_img = imagecreatefromjpeg($w_img);
                break;
            case 3 :
                $water_img = imagecreatefrompng($w_img);
                break;
            default :
                return;
        }
    } else {       
        $ifwaterimage = 0;
        $temp = imagettfbbox(ceil($w_font*2.5), 0, PC_PATH.&#39;libs/data/font/elephant.ttf&#39;, $w_text);
        $width = $temp[2] - $temp[6];
        $height = $temp[3] - $temp[7];
        unset($temp);
    }
    switch($w_pos) {
        case 1:
            $wx = 5;
            $wy = 5;
            break;
        case 2:
            $wx = ($source_w - $width) / 2;
            $wy = 0;
            break;
        case 3:
            $wx = $source_w - $width;
            $wy = 0;
            break;
        case 4:
            $wx = 0;
            $wy = ($source_h - $height) / 2;
            break;
        case 5:
            $wx = ($source_w - $width) / 2;
            $wy = ($source_h - $height) / 2;
            break;
        case 6:
            $wx = $source_w - $width;
     $wy = ($source_h - $height) / 2;
            break;
        case 7:
            $wx = 0;
            $wy = $source_h - $height;
            break;
        case 8:
            $wx = ($source_w - $width) / 2;
            $wy = $source_h - $height;
            break;
        case 9:
            $wx = $source_w - $width;
            $wy = $source_h - $height;
            break;
        case 10:
            $wx = rand(0,($source_w - $width));
            $wy = rand(0,($source_h - $height));
            break;             
        default:
            $wx = rand(0,($source_w - $width));
            $wy = rand(0,($source_h - $height));
            break;
    }
    if($ifwaterimage) {
        if($water_info[2] == 3) {
            imagecopy($source_img, $water_img, $wx, $wy, 0, 0, $width, $height);
        } else {
            imagecopymerge($source_img, $water_img, $wx, $wy, 0, 0, $width, $height, $this->w_pct);
        }
    } else {
        if(!empty($w_color) && (strlen($w_color)==7)) {
            $r = hexdec(substr($w_color,1,2));
            $g = hexdec(substr($w_color,3,2));
            $b = hexdec(substr($w_color,5));
        } else {
            return;
        }
        imagestring($source_img,$w_font,$wx,$wy,$w_text,imagecolorallocate($source_img,$r,$g,$b));
    }
   
    switch($source_info[2]) {
        case 1 :
            imagegif($source_img, $target);
            break;
        case 2 :
            imagejpeg($source_img, $target, $this->w_quality);
            break;
        case 3 :
            imagepng($source_img, $target);
            break;
        default :
            return;
    }
 
    if(isset($water_info)) {
        unset($water_info);
    }
    if(isset($water_img)) {
        imagedestroy($water_img);
    }
    unset($source_info);
    imagedestroy($source_img);
    return true;
}
 
public function check($image) {
    return extension_loaded(&#39;gd&#39;) && preg_match("//.(jpg|jpeg|gif|png)/i", $image, $m) && 
    file_exists($image) && function_exists(&#39;imagecreatefrom&#39;.($m[1] == &#39;jpg&#39; ? &#39;jpeg&#39; : $m[1]));
}
Copy after login

Compared with the part I modified, since phpcms watermark can be managed and set in the background, the watermark method that comes with phpcms obtains the path by reading the configuration file, and obtains the parameter settings by reading the database settings, then These places need to be set manually.

By the way, add a function in the upFile method:

if ($this->watermark) {
    $this->watermark($this->filePath,$this->filePath);
}
Copy after login

Then open the action_upload.php file in the php directory of UEditor Baidu Editor, and add the parameters of whether to add a watermark:

  1. /* 上传配置 */
    $base64 = "upload";
    switch (htmlspecialchars($_GET[&#39;action&#39;])) {
        case &#39;uploadimage&#39;:
            $config = array(
                "pathFormat" => $CONFIG[&#39;imagePathFormat&#39;],
                "maxSize" => $CONFIG[&#39;imageMaxSize&#39;],
                "allowFiles" => $CONFIG[&#39;imageAllowFiles&#39;]
            );
            $fieldName = $CONFIG[&#39;imageFieldName&#39;];
            $watermark = true;
            break;
    Copy after login

Then there is another sentence at the end that needs to be changed to:

  1. /* 生成上传实例对象并完成上传 */
    $up = new Uploader($fieldName, $config, $base64, $watermark);
    Copy after login

    That’s it. This article is mainly to provide ideas and reference.

    form:http://www.uphtm.com/php/255.html


    The above is to add watermarks to pictures uploaded to Baidu UEDITOR editor_ The content of html/css_WEB-ITnose, for more related content, please pay attention to the PHP Chinese website (www.php.cn)!







Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to fix file names or extensions that are too long in Windows 11? How to fix file names or extensions that are too long in Windows 11? Apr 22, 2023 pm 04:37 PM

Have you ever faced any issues while transferring files that prevented you from doing so? Well, many Windows users have recently reported that they faced issues while copying and pasting files into a folder, where an error was thrown saying “The file name of the destination folder is too long”. Additionally, some other Windows users expressed frustration when opening any file and said "the file name or extension is too long" and they were unable to open the file. This disappoints users by not allowing them to transfer files to any other folder. While analyzing the issue, we have come up with a series of solutions that may help alleviate the issue and allow users to transfer files easily. If you are in a similar situation, please see this post for more information. Source: https

How to turn off Windows Defender Smart Screen in Windows 11, 10? How to turn off Windows Defender Smart Screen in Windows 11, 10? Apr 26, 2023 am 11:46 AM

Many Windows users have recently reported that they were annoyed when Windows Defender SmartScreen warned users not to launch applications that were not recognized by Microsoft Windows and they had to click on the "Run anyway" option every time. Windows users are unsure what they can currently do to avoid or disable it. After researching the issue, we found that Windows Defender functionality on the system can be disabled through the Settings application or the Local Group Policy Editor or by adjusting the registry files. By doing this, users will no longer have to face the defender SmartScreen. If your system also encounters

Detailed guide to 15 Python editors/IDEs, there is always one that suits you! Detailed guide to 15 Python editors/IDEs, there is always one that suits you! Aug 09, 2023 pm 05:44 PM

There is no better way to write Python code than using an integrated development environment (IDE). Not only can they make your work simpler and more logical, they can also improve programming experience and efficiency. Everyone knows this. The question is, how to choose the best Python development environment among the many options.

Essential software for C language programming: five good helpers recommended for beginners Essential software for C language programming: five good helpers recommended for beginners Feb 20, 2024 pm 08:18 PM

C language is a basic and important programming language. For beginners, it is very important to choose appropriate programming software. There are many different C programming software options on the market, but for beginners, it can be a bit confusing to choose which one is right for you. This article will recommend five C language programming software to beginners to help them get started quickly and improve their programming skills. Dev-C++Dev-C++ is a free and open source integrated development environment (IDE), especially suitable for beginners. It is simple and easy to use, integrating editor,

Fix the issue where Windows 11/10 login options are disabled Fix the issue where Windows 11/10 login options are disabled May 07, 2023 pm 01:10 PM

Many Windows users have encountered the problem of being unable to log in to Windows 11/10 systems due to failed login attempts or multiple system shutdowns. Users are frustrated because there is nothing they can do about it. Users may forget their PIN code to log into the system, or experience lags when using or installing software, and the system may be forced to shut down multiple times. Therefore, we have compiled a list of the best available solutions that will undoubtedly help consumers solve this problem. To learn more, continue reading this article. Note: Before doing this, make sure you have your system's administrator credentials and Microsoft account password to reset your PIN. If not, wait an hour or so and try with the correct PIN

Ten Python IDEs and code editors highly recommended! Ten Python IDEs and code editors highly recommended! Apr 19, 2023 pm 07:04 PM

Python is a very easy to learn, powerful programming language. Python includes efficient high-level data structures, providing simple and efficient object-oriented programming. The learning process of Python is indispensable without an IDE or code editor, or an integrated development editor (IDE). These Python development tools help developers speed up development using Python and improve efficiency. An efficient code editor or IDE should provide plug-ins, tools and other features that can help developers develop efficiently. 1.VimVim can be said to be the best IDE for Python. Vim is an advanced text editor designed to provide the actual Unix editor 'Vi' functionality and support more and more complete features.

Introduction to Go language development tools: a list of essential tools Introduction to Go language development tools: a list of essential tools Mar 29, 2024 pm 01:06 PM

Title: Introduction to Go language development tools: List of essential tools In the development process of Go language, using appropriate development tools can improve development efficiency and code quality. This article will introduce several essential tools commonly used in Go language development, and attach specific code examples to allow readers to understand their usage and functions more intuitively. 1.VisualStudioCodeVisualStudioCode is a lightweight and powerful cross-platform development tool with rich plug-ins and functions.

How to use ClipChamp: the free Windows 11 video editor How to use ClipChamp: the free Windows 11 video editor Apr 20, 2023 am 11:55 AM

Remember Windows MovieMaker on Windows 7? Since discontinuing Windows MovieMaker, Microsoft hasn't launched any real movie makers. On the other hand, they tried to revamp the Photos app with a small and lightweight built-in video editor. After a long time, Microsoft launched Clipchamp, a better video processor for all Windows 11 devices. In this article, we’ll take a deep dive into how to get everything from the Clipchamp app on your Windows 11 device. How to use Clipchamp – Detailed tutorials are available

See all articles