PHP based on the picture color boundary in different locations to add a watermark method,
In this paper, we describe the method of adding watermark to different locations in PHP according to the color boundary of the picture. 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{//Adjust $lt _w = 30 depending on the situation; $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 useful ah function add_wm_recurse ($NMW _water, $to _dir, $output _dir, $arr) {$dp = Dir ( $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 I used to traverse the image pixel of the ImageIO in Java to get the area of the trousers color. $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 is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/1024918.html www.bkjia.com true http://www.bkjia.com/PHPjc/1024918.html techarticle PHP based on the picture color boundary in different locations to add a watermark method, this article describes the text of PHP according to the picture color boundary in different locations to add a watermark method. Share to everyone for your reference. Concrete implementation of the party ...