Ueditor image watermark

Source: Internet
Author: User
Ueditor image watermark
<无详细内容>

  1. /* PHP image and text watermark class library
  2. Currently, this class library only supports text watermarks. the position is in the lower right corner and the color is random.
  3. Call method:
  4. 1. introduce a class library at the top of the file to be watermarked:
  5. Include_once 'imageclass. php ';
  6. 2. declare a new class:
  7. $ Tpl = new image_fu;
  8. 3. provide parameters for image watermarks:
  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)
  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) {// check whether the image 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 ('Image File: '. $ img.' doesn't exist ');
  37. }
  38. }
  39. Private function imgyesno (){
  40. $ This-> img_info = getimagesize ($ this-> image );
  41. $ This-> img_width = $ this-> img_info [0]; // image width
  42. $ This-> img_height = $ this-> img_info [1]; // picture height
  43. // Check the image type
  44. Switch ($ this-> img_info [2]) {
  45. Case 1: $ this-> img_im = imagecreatefromgif ($ this-> image); break;
  46. Case 2: $ this-> img_im = imagecreatefromjpeg ($ this-> image); break;
  47. Case 3: $ this-> img_im = imagecreatefrompng ($ this-> image); break;
  48. Default: exit ('watermarks are not supported in image format ');
  49. }
  50. $ This-> img_text ();
  51. }
  52. Private function img_text (){
  53. Imagealphablending ($ this-> img_im, true );
  54. // Set the 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 an image
  70. Switch ($ this-> img_info [2]) {// Obtain the background image format
  71. Case 1: imagegif ($ this-> img_im, $ this-> image); break;
  72. Case 2: imagejpeg ($ this-> img_im, $ this-> image); break;
  73. Case 3: imagepng ($ this-> img_im, $ this-> image); break;
  74. Default: exit ('watermark Image failed ');
  75. }
  76. }
  77. // Display the image
  78. Function img_show () {echo 'image. '"border =" 0 "alt ="'. $ this-> img_text. '"/> ';}
  79. // Release the memory
  80. Private function img_nothing (){
  81. Unset ($ this-> img_info );
  82. Imagedestroy ($ this-> img_im );
  83. }
  84. }
  85. ?>

  1. /**
  2. * Created by JetBrains PhpStorm.
  3. * User: taoqili
  4. * Date: 12-7-18
  5. * Time: AM
  6. */
  7. Header ("Content-Type: text/html; charset = utf-8 ");
  8. Error_reporting (E_ERROR | E_WARNING );
  9. Include "Uploader. class. php ";
  10. // Upload the description form name in the image 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, // unit: KB
  17. "AllowFiles" => array (". gif", ". png", ". jpg", ". jpeg", ". bmp ")
  18. );
  19. // Generate and upload the instance object
  20. $ Up = new Uploader ("upfile", $ config );
  21. /**
  22. * Obtain the parameters and array structure corresponding to the uploaded file.
  23. * Array (
  24. * "OriginalName" => "", // original file name
  25. * "Name" => "", // new file name
  26. * "Url" => "", // return address
  27. * "Size" => "", // file size
  28. * "Type" => "", // file type
  29. * "State" => "" // Upload status. if the upload is successful, "SUCCESS" must be returned"
  30. *)
  31. */
  32. $ Info = $ up-> getFileInfo ();
  33. /**
  34. * Return json data to the browser
  35. *{
  36. * 'URL': 'a.jpg ', // path of the saved file
  37. * 'Title': 'hello', // file description, which is added to the title attribute on the front end of the image.
  38. * 'Original': 'B .jpg', // original file name
  39. * 'State': 'success' // Upload status. if the upload succeeds, SUCCESS is returned. other values are returned to the image upload box as they are.
  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"]. "'}";

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.