国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

php利用gd庫(kù)為圖片添加水印

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

本文實(shí)例為大家分享了php利用gd庫(kù)為圖片添加水印的方法,供大家參考,具體內(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);
 
?>

   


Release Notes

Popular Entries