国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

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]));
}

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);
}

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;

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

  1. /* 生成上傳實例對象并完成上傳 */
    $up = new Uploader($fieldName, $config, $base64, $watermark);

    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 (miracleart.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

Undress AI Tool

Undress AI Tool

Undress images for free

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.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

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.

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

How to use Clipchamp video editor on Windows 11 and 10 How to use Clipchamp video editor on Windows 11 and 10 Apr 17, 2023 pm 07:55 PM

How to Install and Use Clipchamp on Windows The Clipchamp app is not yet pre-installed on Windows, but this is a future plan. At the same time, you need to download and install Clipchamp first. To install and use Clipchamp on Windows 11 and Windows 10: Download and install Clipchamp from the Microsoft Store. Once installed, search for Clipchamp in the Start menu to launch it. In the Clipchamp window you will need to log in with your Microsoft or Google account, or use your own personal email

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

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,

The 7 Best Photo Editors for Windows 11 The 7 Best Photo Editors for Windows 11 Apr 28, 2023 pm 09:52 PM

1.GIMPGIMP is a Windows11 image editor that you can use completely free of charge. Why is it worth trying? The program includes most basic adjustment tools like cropping and filters, but you can also take advantage of other professional-grade features for advanced retouching, fixing lens distortions, background replacement, and more. However, some features traditionally available in photo editor toolbars require plugins to be installed in GIMP, such as batch processing with BIMP or blurring with Refocus. Since GIMP is free and offers similar functionality to Adobe Photoshop, you can install it as a free software if you're not ready to invest a lot of money in photo editing.

See all articles