for Baidu UE Editor upload image add watermark function, UE watermark _php Tutorial

Source: Internet
Author: User

for Baidu UE Editor upload image add watermark function, UE watermark


Ueditor Editor upload image is automatically extracted, but the picture does not have a watermark function, the following small series and you see together.

Ueditor Editor does not upload images and watermark function, need to carry out two development, this example is in the PHPCMS system Baidu Editor two times to develop, add upload images and watermark function.

First open the Ueditor Editor file directory of the PHP folder, open the Uploader.class.php, the Phpcms watermark method to copy, add to this class all member methods of the last side, and then modify the following:

Image watermark Public Function watermark ($source, $target = ", $w _pos =", $w _img = ", $w _text = ' 99danji ', $w _font = 8, $w _colo  r = ' #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. ' Libs/data/font/elephant.ttf ', $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: $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, $heigh    T);    } 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 (' gd ') && preg_match ("/\. ( jpg|jpeg|gif|png)/I ", $image, $m) && file_exists ($image) && function_exists (' Imagecreatefrom '. ( $m [1] = = ' jpg '? ' JPEG ': $m [1]);}

Compared to the part I modified, because the PHPCMS watermark can be managed in the background settings, the PHPCMS comes with the watermark method by reading the configuration file to get the path, and read the database settings to get the parameter settings, then these places need to be set manually.

By the way, the Upfile method also adds a function:

Copy the Code code as follows:
if ($this->watermark) {
$this->watermark ($this->filepath, $this->filepath);
}

Then open the Ueditor Baidu Editor php directory under the action_upload.php file, plus whether to add the watermark parameters:

/* Upload configuration */$base = "upload"; switch (Htmlspecialchars ($_get[' action ')) {case  ' uploadimage ':    $config = Array ( c4/> "Pathformat" = $CONFIG [' Imagepathformat '],      "maxSize" and "Imagemaxsize" and "Allowfiles" ("the"),      "The" ["] = > $CONFIG [' imageallowfiles ']    );    $fieldName = $CONFIG [' Imagefieldname '];    $watermark = true;    Break

Then there is another sentence to be changed:

Copy the Code code as follows:
/* Generate the Upload instance object and complete the upload */
$up = new Uploader ($fieldName, $config, $base, $watermark);

This will be done, this article is mainly to provide ideas and reference.

The above is the whole content of this article, I hope you can like, can be useful to everyone using UE editor.

http://www.bkjia.com/PHPjc/985282.html www.bkjia.com true http://www.bkjia.com/PHPjc/985282.html techarticle for Baidu UE Editor upload image to add watermark function, UE watermark Ueditor Editor upload image is automatically extracted, but the picture does not have a watermark function, the following small series and you see together. ...

  • 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.