Heim >Backend-Entwicklung >PHP-Tutorial >PHP根据图片色阶确定位置打水印_PHP教程

PHP根据图片色阶确定位置打水印_PHP教程

WBOY
WBOYOriginal
2016-07-13 17:42:47928Durchsuche

直接分享源码

<ol class="dp-c">
<li class="alt"><span><span><?php     </span></span></span></li>
<li>
<span>    </span><span class="keyword">function</span><span> add_wm(</span><span class="vars">$nmw_water</span><span>, </span><span class="vars">$src_file</span><span>, </span><span class="vars">$output_file</span><span>, </span><span class="vars">$x</span><span>, </span><span class="vars">$y</span><span>) {    </span>
</li>
<li class="alt">
<span>        </span><span class="keyword">if</span><span>(</span><span class="func">file_exists</span><span>(</span><span class="vars">$output_file</span><span>))    </span>
</li>
<li>
<span>            </span><span class="keyword">return</span><span>;    </span>
</li>
<li class="alt"><span>    </span></li>
<li>
<span>        </span><span class="vars">$w1</span><span> = MagickGetImageWidth(</span><span class="vars">$nmw_water</span><span>);    </span>
</li>
<li class="alt">
<span>        </span><span class="vars">$h1</span><span> = MagickGetImageHeight(</span><span class="vars">$nmw_water</span><span>);    </span>
</li>
<li><span>    </span></li>
<li class="alt">
<span>        </span><span class="vars">$nmw</span><span> =NewMagickWand();    </span>
</li>
<li>
<span>        MagickReadImage(</span><span class="vars">$nmw</span><span>, </span><span class="vars">$src_file</span><span>);    </span>
</li>
<li class="alt"><span>    </span></li>
<li>
<span>        </span><span class="comment">// 默认的加水印位置调整   </span><span> </span>
</li>
<li class="alt">
<span>        </span><span class="vars">$lt_w</span><span> = 50;    </span>
</li>
<li>
<span>        </span><span class="vars">$lt_h</span><span> = 50;    </span>
</li>
<li class="alt"><span>    </span></li>
<li>
<span>        </span><span class="keyword">if</span><span>(</span><span class="vars">$x</span><span> == 0){    </span>
</li>
<li class="alt">
<span>            </span><span class="vars">$w</span><span> = MagickGetImageWidth(</span><span class="vars">$nmw</span><span>);    </span>
</li>
<li>
<span>            </span><span class="vars">$h</span><span> = MagickGetImageHeight(</span><span class="vars">$nmw</span><span>);    </span>
</li>
<li class="alt"><span>    </span></li>
<li>
<span>            </span><span class="vars">$x</span><span> = </span><span class="vars">$w</span><span>;    </span>
</li>
<li class="alt">
<span>            </span><span class="vars">$y</span><span> = </span><span class="vars">$h</span><span>;    </span>
</li>
<li>
<span>        }</span><span class="keyword">else</span><span>{    </span>
</li>
<li class="alt">
<span>            </span><span class="comment">// 根据具体情况调整   </span><span> </span>
</li>
<li>
<span>            </span><span class="vars">$lt_w</span><span> = 30;    </span>
</li>
<li class="alt">
<span>            </span><span class="vars">$lt_h</span><span> = 40;    </span>
</li>
<li><span>        }    </span></li>
<li class="alt"><span>    </span></li>
<li>
<span>        MagickCompositeImage(</span><span class="vars">$nmw</span><span>, </span><span class="vars">$nmw_water</span><span>, MW_OverCompositeOp, </span><span class="vars">$x</span><span> - </span><span class="vars">$w1</span><span> - </span><span class="vars">$lt_w</span><span>, </span><span class="vars">$y</span><span> - </span><span class="vars">$h1</span><span> - </span><span class="vars">$lt_h</span><span>);    </span>
</li>
<li class="alt">
<span>        MagickWriteImage(</span><span class="vars">$nmw</span><span>, </span><span class="vars">$output_file</span><span>);    </span>
</li>
<li><span>    </span></li>
<li class="alt">
<span>        DestroyMagickWand(</span><span class="vars">$nmw</span><span>);            </span>
</li>
<li><span>    }    </span></li>
<li class="alt"><span>    </span></li>
<li>
<span>    </span><span class="comment">// 还是groovy的eachFileRecurse好用啊   </span><span> </span>
</li>
<li class="alt">
<span>    </span><span class="keyword">function</span><span> add_wm_recurse(</span><span class="vars">$nmw_water</span><span>, </span><span class="vars">$to_dir</span><span>, </span><span class="vars">$output_dir</span><span>, </span><span class="vars">$arr</span><span>) {    </span>
</li>
<li>
<span>        </span><span class="vars">$dp</span><span> = dir(</span><span class="vars">$to_dir</span><span>);    </span>
</li>
<li class="alt">
<span>        </span><span class="keyword">while</span><span>(</span><span class="vars">$file</span><span>=</span><span class="vars">$dp</span><span>->read()){    </span>
</li>
<li>
<span>            </span><span class="keyword">if</span><span>(</span><span class="vars">$file</span><span> != </span><span class="string">.</span><span> && </span><span class="vars">$file</span><span> != </span><span class="string">..</span><span>){    </span>
</li>
<li class="alt">
<span>                </span><span class="keyword">if</span><span>(</span><span class="func">is_dir</span><span>(</span><span class="vars">$to_dir</span><span> . </span><span class="string">/</span><span> . </span><span class="vars">$file</span><span>)){    </span>
</li>
<li>
<span>                    </span><span class="func">mkdir</span><span>(</span><span class="vars">$output_dir</span><span> . </span><span class="string">/</span><span> . </span><span class="vars">$file</span><span>);    </span>
</li>
<li class="alt">
<span>                    add_wm_recurse(</span><span class="vars">$nmw_water</span><span>, </span><span class="vars">$to_dir</span><span> . </span><span class="string">/</span><span> . </span><span c>
<p align="left"></p>
<div style="display:none;">
<span id="url" itemprop="url">http://www.bkjia.com/PHPjc/486032.html</span><span id="indexUrl" itemprop="indexUrl">www.bkjia.com</span><span id="isOriginal" itemprop="isOriginal">true</span><span id="isBasedOnUrl" itemprop="isBasedOnUrl">http://www.bkjia.com/PHPjc/486032.html</span><span id="genre" itemprop="genre">TechArticle</span><span id="description" itemprop="description">直接分享源码 ?php function add_wm( $nmw_water , $src_file , $output_file , $x , $y ){ if ( file_exists ( $output_file )) return ; $w1 =MagickGetImageWidth( $nmw_water ); $h1...</span>
</div>
<div class="art_confoot"></div>
</span>
</li>
</ol>
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn