PHP _php techniques to add watermarks to different locations based on image color boundaries

Source: Internet
Author: User
Tags php programming

This article illustrates how PHP adds watermarks to different locations based on the color boundaries of the image. Share to everyone for your reference. The implementation method is as follows:

function Add_wm ($NMW _water, $src _file, $output _file, $x, $y) {if (file_exists ($output _file)) return;    
    $w 1 = magickgetimagewidth ($NMW _water);    
    $h 1 = magickgetimageheight ($NMW _water);    
    $NMW =newmagickwand ();    
    Magickreadimage ($NMW, $src _file);    
    The default watermark position adjustment $lt _w = 50;    
    $lt _h = 50;    
      if ($x = = 0) {$w = Magickgetimagewidth ($NMW);    
      $h = Magickgetimageheight ($NMW);    
      $x = $w;    
    $y = $h;    
      }else{//Adjusted $LT _w = 30 According to the specific conditions;    
    $lt _h = 40;    
    Magickcompositeimage ($NMW, $NMW _water, Mw_overcompositeop, $x-$w 1-$lt _w, $y-$h 1-$lt _h);    
    Magickwriteimage ($NMW, $output _file);        
  Destroymagickwand ($NMW); //or Groovy eachfilerecurse. function Add_wm_recurse ($NMW _water, $to _dir, $output _dir, $arr) {$DP = d    
    IR ($to _dir); while ($file = $DP->read ()) {if ($file!= '. ' && $file!= ' ... '){if (Is_dir $to _dir.) '/' . $file)) {mkdir ($output _dir). '/' .    
          $file); Add_wm_recurse ($NMW _water, $to _dir. '/' . $file, $output _dir. '/' .    
        $file, $arr); }else{if (!array_key_exists ($to _dir. '/' .    
          $file, $arr)) {continue; $sub _arr = $arr [$to _dir. '/' .    
          $file];    
            if ($sub _arr) {$x = Intval ($sub _arr[0]);    
            $y = Intval ($sub _arr[1]); ADD_WM ($NMW _water, $to _dir. '/' . $file, $output _dir. '/' .    
          $file, $x, $y);    
  $DP->close ()}}};    
  } $to _dir = './resized ';    
  $output _dir = './output ';    
  This is the coordinate array (POSX, posy) $arr = Array (Array (50, 50)) that matches the color of the trousers with the Java ImageIO traversing the image pixel;    
  $water = './water.png ';    
  $NMW _water =newmagickwand ();    
  Magickreadimage ($NMW _water, $water); Add_wm_recurse ($NMW _water, $to _dir, $output _dIR, $arr);

 Destroymagickwand ($NMW _water);

I hope this article will help you with your PHP programming.

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.