php图片添加水印例子
内容摘要
图片添加水印我相信各位朋友都知道的,今天我们来看一段php的图片添加水印例子,希望文章能够帮助到各位朋友。
<?php
/**
* 图片添加水印
* $target 源文件路
<?php
/**
* 图片添加水印
* $target 源文件路
文章正文
图片添加水印我相信各位朋友都知道的,今天我们来看一段php的图片添加水印例子,希望文章能够帮助到各位朋友。
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 | <?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; } ?> |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持phpstudy。
代码注释