日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

用php程序能消除水印吗,php——水印

發布時間:2024/10/8 php 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 用php程序能消除水印吗,php——水印 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

很多開發語言都會實現水印功能,之前我用OC和swift都實現過,最近學下php,順便練下手,記錄下以便查閱。

//水印

function water($source,$water = '1_jaccty.png',$position = 0,$alpha = 100,$type = "jpeg",$path = 'waterTest',$isRandName = true){

//打開圖片

$sourceRes = open($source);

$waterRes = open($water);

//獲取原圖寬高

$source_info = getimagesize($source);

$source_w = $source_info[0];

$source_h = $source_info[1];

//獲取水印的寬高

$water_info = getimagesize($water);

$water_w = $water_info[0];

$water_h = $water_info[1];

//計算位置

$image_slipw = $source_w / 3;

$image_sliph = $source_h / 3;

$position_x = ($position % 3-1)*$image_slipw;

$position_y = floor($position / 3)*$image_sliph;

if ($position!=0) {

$x = mt_rand($position_x,$position_x+$image_slipw-$water_w);

$y = mt_rand($position_y,$position_y+$image_sliph-$water_h);

}else{

$x = mt_rand(0,$source_w-$water_w);

$y = mt_rand(0,$source_h-$water_h);

}

//合并

imagecopymerge($sourceRes, $waterRes, $x, $y, 0, 0, $water_w, $water_h, $alpha);

$imageType = 'image'.$type;//根據$type來調用哪個函數

/*

imagepng();

imagejpeg();

imagewbmp();

*/

//處理path問題

if ($isRandName) {

$name = uniqid().'.'.$type;

}else{

$pathInfo = pathinfo($source);

$name = $pathInfo['filename'].'.'.$type;

}

$path = rtrim($path,'/').'/'.$name;//防止已有/斜線

$imageType($sourceRes,$path);//畫圖

imagedestroy($sourceRes);

imagedestroy($waterRes);

}

//打開圖片的函數

function open($path){

if (!file_exists($path)) {

exit('文件不存在');

}

$info = getimagesize($path);

switch ($info['mime']) {

case 'image/jpeg':

case 'image/jpg':

case 'image/pjpeg':

$res = imagecreatefromjpeg($path);

break;

case 'image/png':

$res = imagecreatefrompng($path);

break;

case 'image/gif':

$res = imagecreatefromgif($path);

break;

case 'image/wbmp':

case 'image/bmp':

$res = imagecreatefromwbmp($path);

break;

}

return $res;

}

$source = "1.jpg";

water($source);

?>

總結

以上是生活随笔為你收集整理的用php程序能消除水印吗,php——水印的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。