Ueditor Picture and Watermark

Source: Internet
Author: User
<无详细内容>
  1. /*php Picture Plus text Watermark class Library
  2. This kind of library temporarily supports only text watermark, the position is the bottom right corner, color random
  3. Call Method:
  4. 1, in the need to watermark the top of the file to introduce the class library:
  5. Include_once ' imageclass.php ';
  6. 2. Declaring a new class:
  7. $tpl =new Image_fu;
  8. 3. Provide parameters for image watermark:
  9. $TPL->img (image path, watermark text, font path, font size, font angle);
  10. For example: $tpl->img (' abc.jpg ', ' This is the watermark text ', ' Ziti.ttf ', 30,0)
  11. */
  12. Class image_fu{
  13. Private $image;
  14. Private $img _info;
  15. Private $img _width;
  16. Private $img _height;
  17. Private $img _im;
  18. Private $img _text;
  19. Private $img _ttf= ';
  20. Private $img _new;
  21. Private $img _text_size;
  22. Private $img _JD;
  23. function img ($img = ', $txt = ', $ttf = ', $size =12, $jiaodu =0) {
  24. if (Isset ($img) &&file_exists ($img)) {//detect if a picture exists
  25. $this->image = $img;
  26. $this->img_text= $txt;
  27. $this->img_text_size= $size;
  28. $this->img_jd= $jiaodu;
  29. if (file_exists ($ttf)) {
  30. $this->img_ttf= $ttf;
  31. }else{
  32. Exit (' Font file: '. $ttf. ' does not exist! ');
  33. }
  34. $this->imgyesno ();
  35. }else{
  36. Exit (' picture file: '. $img. ' does not exist ');
  37. }
  38. }
  39. Private Function Imgyesno () {
  40. $this->img_info =getimagesize ($this->image);
  41. $this->img_width = $this->img_info[0];//picture width
  42. $this->img_height= $this->img_info[1];//Pictures High
  43. Detecting picture types
  44. Switch ($this->img_info[2]) {
  45. Case 1: $this->img_im = imagecreatefromgif ($this->image);
  46. Case 2: $this->img_im = imagecreatefromjpeg ($this->image);
  47. Case 3: $this->img_im = imagecreatefrompng ($this->image);
  48. Default:exit (' image format does not support Watermark ');
  49. }
  50. $this->img_text ();
  51. }
  52. Private Function Img_text () {
  53. Imagealphablending ($this->img_im,true);
  54. Set color
  55. $color =imagecolorallocate ($this->img_im,255,255,255);
  56. $txt _height= $this->img_text_size;
  57. $txt _jiaodu= $this->img_jd;
  58. $ttf _im=imagettfbbox ($txt _height, $txt _jiaodu, $this->img_ttf, $this->img_text);
  59. $w = $ttf _im[2]-$ttf _im[6];
  60. $h = $ttf _im[3]-$ttf _im[7];
  61. $w = $ttf _im[7];
  62. $h = $ttf _im[8];
  63. unset ($ttf _im);
  64. $txt _y = $this->img_height*0.5;
  65. $txt _x = $this->img_width*0.2;
  66. $txt _y = 0;
  67. $txt _x = 0;
  68. $this->img_new= @imagettftext ($this->img_im, $txt _height, $txt _jiaodu, $txt _x, $txt _y, $color, $this->img_ TTF, $this->img_text);
  69. @unlink ($this->image);//Delete picture
  70. Switch ($this->img_info[2]) {//Get the format of the background picture
  71. Case 1:imagegif ($this->img_im, $this->image);
  72. Case 2:imagejpeg ($this->img_im, $this->image);
  73. Case 3:imagepng ($this->img_im, $this->image);
  74. Default:exit (' watermark image failed ');
  75. }
  76. }
  77. Show pictures
  78. function Img_show () {echo ' image. ' border= ' 0 "alt=" '. $this->img_text. '/> ';}
  79. Freeing memory
  80. Private Function img_nothing () {
  81. unset ($this->img_info);
  82. Imagedestroy ($this->img_im);
  83. }
  84. }
  85. ?>
Copy Code
  1. /**
  2. * Created by JetBrains Phpstorm.
  3. * User:taoqili
  4. * date:12-7-18
  5. * Time: 10:42
  6. */
  7. Header ("content-type:text/html; Charset=utf-8 ");
  8. Error_reporting (E_error | e_warning);
  9. Include "Uploader.class.php";
  10. The description form name in the Upload picture box,
  11. $title = Htmlspecialchars ($_post[' Pictitle '), ent_quotes);
  12. $path = Htmlspecialchars ($_post[' dir '), ent_quotes);
  13. Upload Configuration
  14. $config = Array (
  15. "Savepath" = ($path = = "1"? "upload/": "upload1/"),
  16. "MaxSize" = 1000,//per unit KB
  17. "Allowfiles" = = Array (". gif", ". png", ". jpg", ". jpeg", ". bmp")
  18. );
  19. Generate an Upload instance object and complete the upload
  20. $up = new Uploader ("Upfile", $config);
  21. /**
  22. * Get the various parameters of the uploaded file, array structure
  23. * Array (
  24. * "Originalname" + "",//Original file name
  25. * "Name" = "" ",//New file name
  26. * "url" = "",//Address returned
  27. * "Size" = "" ",//File size
  28. * "Type" = "" ",//file type
  29. * "state" = "" "//upload status, must return" SUCCESS "when upload is successful
  30. * )
  31. */
  32. $info = $up->getfileinfo ();
  33. /**
  34. * Return data JSON data to the browser
  35. * {
  36. * ' url ': ' a.jpg ',//file path after saving
  37. * ' title ': ' Hello ',//File description, the front end will be added to the title property on the picture
  38. * ' original ': ' b.jpg ',//original file name
  39. * ' state ': ' SUCCESS '//upload status, return SUCCESS on success, any other value will be returned to the picture upload box
  40. * }
  41. */
  42. /* include "imgwater.php";
  43. $tpl =new Image_fu;
  44. $tpl->img ($info [' url '], ' http://www.zgxbzh.com/', ' SIMSUN.TTC ', 30,0);
  45. echo "{' URL ': '". $info ["url"]. "', ' title ': '". $title. "', ' original ': '". $info ["Originalname"]. "', ' state ': '". $info ["state"]. "'}";
Copy Code
  • Related Article

    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.