php圖片添加水印例子
更新時(shí)間:2016年07月20日 11:08:45 投稿:lijiao
這篇文章主要為大家分享了一段php圖片添加水印例子,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
圖片添加水印我相信各位朋友都知道的,今天我們來(lái)看一段php的圖片添加水印例子,希望文章能夠幫助到各位朋友。
<?php
/**
* 圖片添加水印
* $target 源文件路徑
* $wtrmrk_file 水印圖片路徑
* $newcopy 添加水印后的圖片路徑
*
*/
public function watermark_image($target, $wtrmrk_file, $newcopy) {
$watermark = imagecreatefrompng($wtrmrk_file);
imagealphablending($watermark, false);
imagesavealpha($watermark, true);
$img = imagecreatefromjpeg($target);
$img_w = imagesx($img);
$img_h = imagesy($img);
$wtrmrk_w = imagesx($watermark);
$wtrmrk_h = imagesy($watermark);
$dst_x = ($img_w ) – ($wtrmrk_w); // For centering the watermark on any image //phpfensi.com
$dst_y = ($img_h) – ($wtrmrk_h ); // For centering the watermark on any image
imagecopy($img, $watermark, $dst_x, $dst_y, 0, 0, $wtrmrk_w, $wtrmrk_h);
imagejpeg($img, $newcopy, 100);
imagedestroy($img);
imagedestroy($watermark);
//return $img;
}
?>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
關(guān)于在php.ini中添加extension=php_mysqli.dll指令的說(shuō)明
關(guān)于在php.ini中添加extension=php_mysqli.dll指令的說(shuō)明...2007-06-06
window+nginx+php環(huán)境配置 附配置搭配說(shuō)明
官方并不建議你將Non Thread Safe 應(yīng)用于生產(chǎn)環(huán)境,所以我們選擇Thread Safe 版本的PHP來(lái)使用。2010-12-12
實(shí)現(xiàn)PHP多線(xiàn)程異步請(qǐng)求的3種方法
實(shí)現(xiàn)PHP多線(xiàn)程異步請(qǐng)求的方法有很多,在本文整理了3種不多的常用方法,大家可以參考下2014-01-01

