The example of this article describes the PHP based on the color of the image in different locations of the watermark method. Share to everyone for your reference. The implementation methods are as follows:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26-27--28 29---30 31--32 33 34 35 36 37 38-39 40 41 42 45 46 47 48 49 50 51 52 53 54 55 56 57-58 |
function Add_wm ($NMW _water, $src _file, $output _file, $x, $y) {if (file_exists ($output _file)) return; $w 1 = magickgetimage Width ($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{///adjustment $lt _w = $lt _h = 40 in accordance with the specific circumstances;} Magickcompositeimage ($NMW, $NMW _water, Mw_overcompositeop, $x-$w 1-$lt _w, $y-$h 1-$lt _h); Magickwriteimage ($NMW, $output _file); Destroymagickwand ($NMW); //or Groovy's eachfilerecurse is handy. function Add_wm_recurse ($NMW _water, $to _dir, $output _dir, $arr) {$dp = Dir ($to _dir); whi Le ($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.