PHP watermarks images based on their color levels

Source: Internet
Author: User

Share Source Code directly

 
  1. <? Php
  2. Function add_wm ($ nmw_water, $ src_file, $ output_file, $ x, $ y ){
  3. If (file_exists ($ output_file ))
  4. Return;
  5. $ W1 = MagickGetImageWidth ($ nmw_water );
  6. $ H1 = MagickGetImageHeight ($ nmw_water );
  7. $ Nmw = NewMagickWand ();
  8. MagickReadImage ($ nmw, $ src_file );
  9. // Adjust the default watermark position
  10. $ Lt_w = 50;
  11. $ Lt_h = 50;
  12. If ($ x = 0 ){
  13. $ W = MagickGetImageWidth ($ nmw );
  14. $ H = MagickGetImageHeight ($ nmw );
  15. $ X = $ w;
  16. $ Y = $ h;
  17. } Else {
  18. // Adjust according to the actual situation
  19. $ Lt_w = 30;
  20. $ Lt_h = 40;
  21. }
  22. MagickCompositeImage ($ nmw, $ nmw_water, MW_OverCompositeOp, $ x-$ w1-$ lt_w, $ y-$ h1-$ lt_h );
  23. MagickWriteImage ($ nmw, $ output_file );
  24. DestroyMagickWand ($ nmw );
  25. }
  26. // It's still groovy's eachFileRecurse easy to use.
  27. Function add_wm_recurse ($ nmw_water, $ to_dir, $ output_dir, $ arr ){
  28. $ Dp = dir ($ to_dir );
  29. While ($ file = $ dp-> read ()){
  30. If ($ file! =. & $ File! = ..){
  31. If (is_dir ($ to_dir./. $ file )){
  32. Mkdir ($ output_dir./. $ file );
  33. Add_wm_recurse ($ nmw_water, $ to_dir ./.

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.