Ueditor Editor realizes upload picture automatically add watermark

Source: Internet
Author: User

itself is not to upload images to add watermark function, want to upload the time to add a picture watermark, but also very simple. Take Ueditor 1.2.6 as an example, open the imageup.php file under the PHP directory and look for "$info = $up->getfileinfo ();", add the following code below this code:

Then save it, and it's OK. Note, however, that $water _img = "watermark.png";//Watermark file (replace here with the watermark you want).

/* Add watermark Start/*
$water _img = "Watermark.png"; Watermark file (replace here with the watermark you want)
$img _min_w = 350; Adding a watermark requires the minimum width (px) of the picture, and does not add a watermark when it is less than this width
$img _min_h = 60; Adding a watermark requires a minimum image height (px)
$new _img = $ori _img = $info ["url"];

$original = getimagesize ($ori _img); To get a picture of the information, you can Print_r ($original) that it is an array
if ($original [0]> $img _min_w&& $original [1]> $img _min_h) {//watermark is added when the picture is wider than 300px
$watermark = getimagesize ($water _img);

$s _original = imgcreatefrom ($ori _img, $original [2]); $original [2] is a picture type, where 1 represents GIF, 2 for JPG, 3 for PNG
$s _watermark = imgcreatefrom ($water _img, $watermark [2]);

$posX = $original [0]-$watermark [0]-6; x coordinate (lower right corner)
$poxY = $original [1]-$watermark [1]-3; Y-coordinate (lower right corner)

Hit watermark
Imagecopy ($s _original, $s _watermark, $posX, $poxY, 0, 0, $watermark [0], $watermark [1]);
Imagejpeg ($s _original, $new _img); Generate a new picture
}

Create a new image from a file type
function Imgcreatefrom ($img _src, $val) {
Switch ($val) {
Case 1: $img = imagecreatefromgif ($img _src);
Break
Case 2: $img = Imagecreatefromjpeg ($img _src);
Break
Case 3: $img = imagecreatefrompng ($img _src);
Break
}
return $img;
}
/* Add watermark End/*

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.