亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

php利用gd庫為圖片添加水印

??? 2016-12-27 13:14:41 297
????:本文實(shí)例為大家分享了php利用gd庫為圖片添加水印的方法,供大家參考,具體內(nèi)容如下<?php $dst_path = '1.jpg';//目標(biāo)圖片 $src_path = 'logo1.png';//水印圖片   //創(chuàng)建圖片的實(shí)例 $dst = imagecreatefromstring(

本文實(shí)例為大家分享了php利用gd庫為圖片添加水印的方法,供大家參考,具體內(nèi)容如下

<?php
$dst_path = '1.jpg';//目標(biāo)圖片
$src_path = 'logo1.png';//水印圖片
 
//創(chuàng)建圖片的實(shí)例
$dst = imagecreatefromstring(file_get_contents($dst_path));
$src = imagecreatefromstring(file_get_contents($src_path));
//獲取水印圖片的寬高
list($src_w, $src_h) = getimagesize($src_path);
//將水印圖片復(fù)制到目標(biāo)圖片上,最后個(gè)參數(shù)50是設(shè)置透明度,這里實(shí)現(xiàn)半透明效果,兩個(gè)20是控制水印坐標(biāo)位置
imagecopymerge($dst, $src, 20, 20, 0, 0, $src_w, $src_h, 50);
//如果水印圖片本身帶透明色,則使用imagecopy方法
//imagecopy($dst, $src, 10, 10, 0, 0, $src_w, $src_h);
//輸出圖片
list($dst_w, $dst_h, $dst_type) = getimagesize($dst_path);
switch ($dst_type) {
 case 1://GIF
 header('Content-Type: image/gif');
 imagegif($dst);
 break;
 case 2://JPG
 header('Content-Type: image/jpeg');
 imagejpeg($dst);
 break;
 case 3://PNG
 header('Content-Type: image/png');
 imagepng($dst);
 break;
 default:
 break;
}
imagedestroy($dst);
imagedestroy($src);
 
?>

更多關(guān)于php利用gd庫為圖片添加水印請(qǐng)關(guān)注PHP中文網(wǎng)(ipnx.cn)其它文章!

??? ??

?? ??