春天的水仙花在清晨绽放 (© LedyX/Shutterstock)

Welcom to 评论 - lizhenqiu blog!

    #58

    作者:广西
    海康SMB对版本有要求,一定要开SMB V1,且共享的文件系统要求是FAT格式,NTFS应该是不行的,路由器无法选择SMB版本的话就没办法了可以尝试NFS无密码方式
    #,广西,2023-06-30,03:08:20, 海康摄像头 NFS Samba NAS服务器挂载目录失败,目录无效或者用户名密码错误
    文章:Centos7下Samba服务器配置  发表时间:2023-06-30, 03:07:58  
    展开↯

    #59

    作者:广西南宁市
    流媒体服务框架 ZLMediaKit
    使用踩坑之旅播报文章

    史上本没有坑,踩的人多了,坑就更多了
    获取代码 #国内用户推荐从同步镜像网站gitee下载 git clone --depth 1 https://gitee.com/xia-chu/ZLMediaKitcd ZLMediaKit#千万不要忘记执行这句命令git submodule update --init 安装编译器 sudo yum -y install gccsudo yum -y install gcc-c++移除旧版本cmakeyum remove cmake -ywget https://cmake.org/files/v3.6/cmake-3.6.2.tar.gztar -zxvf cmake-3.6.2.tar.gzcd cmake-3.6.2/./bootstrap --prefix=/usr/localmake && make installcmake --version# 安装 .net# 注册 Microsoft 密钥和源sudo rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm# 安装 .NET Core SDKyum install dotnet-sdk-3.1# 验证是否安装成功dotnet --version 安装辅助工具 sudo yum install epel-releasesudo yum localinstall --nogpgcheck https://download1.rpmfusion.org/free/el/rpmfusion-free-release-7.noarch.rpmsudo yum install ffmpeg ffmpeg-develffmpeg -version 编译核心代码 cd ZLMediaKitmkdir buildcd buildcmake ..make -j4 注意:make -j4 失败的话,尝试用 make 继续安装 编译成功后 在 `/root/ZLMediaKit/release/linux/Debug` 目录下生成 MediaServer 可执行文件;#通过-h可以了解启动参数./MediaServer -h#以守护进程模式启动./MediaServer -d &# 配置文件/root/ZLMediaKit/release/linux/Debug/config.ini(注意修改[ffmpeg]相关参数,修改 bin=/usr/bin/ffmpeg 指定 ffmpeg 的执行文件,修改 cmd='XXXXX' 变更推拉流的相关参数)`/root/ZLMediaKit/release/linux/Debug/ffmpeg` 下查看 ffmpeg 相关日志,因日志数量众多,记得清空之前的文件。 使用实例 将外部直播流通过 ZLMediaKit 转发出来 http://139.155.205.208/index/api/addFFmpegSource具体参数:secret:035c73f7-bb6b-4889-a715-d9eb2d1925ccsrc_url:http://ivi.bupt.edu.cn/hls/cctv1hd.m3u8dst_url:rtmp://127.0.0.1/live/testtimeout_ms:10000 观看方式: rtsp://139.155.205.208/live/test
    Run code
    Cut to clipboard
      #,广西南宁市,2023-06-21,14:56:45, ZlmediaKit简单使用
      开源媒体服务器: ZlMediaKit
      文章:centos7中用shell脚本一键安装ZLMediaKit并运行  发表时间:2023-06-21, 14:54:14  
      展开↯

      #60

      作者:广西南宁市
      linux上git克隆命令,Git clone命令用法
      git clone是git中常用的命令,其作用是将存储库克隆到新目录中。那么在git中,git clone具体该如何用呢?

      更快更轻松的学习Git,请点击Git微课

      git clone命令的作用是将存储库克隆到新目录中,为克隆的存储库中的每个分支创建远程跟踪分支(使用git branch -r可见),并从克隆检出的存储库作为当前活动分支的初始分支。

      在克隆之后,没有参数的普通git提取将更新所有远程跟踪分支,并且没有参数的git pull将另外将远程主分支合并到当前主分支(如果有的话)。

      此默认配置通过在refs/remotes/origin下创建对远程分支头的引用,并通过初始化remote.origin.url和remote.origin.fetch配置变量来实现。

      执行远程操作的第一步,通常是从远程主机克隆一个版本库,这时就要用到git clone命令。$ git clone

      比如,克隆jQuery的版本库。$ git clone http://github.com/jquery/jquery.git

      该命令会在本地主机生成一个目录,与远程主机的版本库同名。如果要指定不同的目录名,可以将目录名作为git clone命令的第二个参数。$ git clone

      git clone支持多种协议,除了HTTP(s)以外,还支持SSH、Git、本地文件协议等。

      在默认情况下,Git会把"Git URL"里最后一级目录名的'.git'的后辍去掉,做为新克隆(clone)项目的目录名: (例如. git clone http://git.kernel.org/linux/kernel/git/torvalds/linux-2.6.git 会建立一个目录叫'linux-2.6')$ git clone http[s]://example.com/path/to/repo.git

      $ git clone http://git.oschina.net/yiibai/sample.git

      $ git clone ssh://example.com/path/to/repo.git

      $ git clone git://example.com/path/to/repo.git

      $ git clone /opt/git/project.git

      $ git clone file:///opt/git/project.git

      $ git clone ftp[s]://example.com/path/to/repo.git

      $ git clone rsync://example.com/path/to/repo.git

      SSH协议还有另一种写法。$ git clone [user@]example.com:path/to/repo.git

      通常来说,Git协议下载速度最快,SSH协议用于需要用户认证的场合。

      应用场景示例

      从上游克隆下来:$ git clone git://git.kernel.org/pub/scm/.../linux.git mydir

      $ cd mydir

      $ make # 执行代码或其它命令

      在当前目录中使用克隆,而无需检出:$ git clone -l -s -n . ../copy

      $ cd ../copy

      $ git show-branch

      从现有本地目录借用从上游克隆:$ git clone --reference /git/linux.git

      git://git.kernel.org/pub/scm/.../linux.git

      mydir

      $ cd mydir

      创建一个裸存储库以将您的更改发布给公众:$ git clone --bare -l /home/proj/.git /pub/scm/proj.git
      文章:宝塔Mysql配置Navicat远程连接  发表时间:2023-06-19, 14:16:08  
      展开↯

      #61

      作者:广西
      Zone.Identifier
      取消复制文件到共享目录自动生成:Zone.Identifier文件

      Windows复制文件到共享目录会生成一个【文件名:Zone.Identifier】的文件,像我复制文件到wsl目录下就经常会有这种情况

      不过也不是每次都会生成,具体什么情况会生成这样的文件我也不清楚,只知道这个对我来说很多余。

      Zone.Identifier文件描述:文件包含元数据描述与另一个文件相关联的安全区域,当一个文件从互联网下载或收到的电子邮件附件自动生成,往往由Internet Explorer创建的。

      区标识符的文件也被称为“备用数据流” (ADS)的文件,因为它们仅用于描述其它文件。他们有相同的文件名与原始文件,后跟一个冒号和文本“ Zone.Identifier 。 ”例如,将文件“ download.exe : Zone.Identifier ”可能与命名下载的文件保存“ download.exe 。 ”

      Windows使用区域标识符文件来管理安全设置下载的文件。由于文件是由操作系统所引用,它们并不意味着被手动打开。当原始文件被删除,相应的区域识别符文件是由操作系统自动删除。区标识符文件默认是隐藏的,但如果“显示隐藏文件”选项开启时可能会显示。

      对于我来说没什么卵用,而且每次复制完文件都要手动删除一次,烦人得很,于是网上搜了个解决方法,这里分享一下。
      打开组策略(按win+r,输入gpedit.msc回车)
      打开【用户配置->管理模板->Windows 组件->附件管理器】

      编辑右侧的文件附件中不保留区域信息,选择已启用然后点击确定保存就可以。

      文章:常用命令笔记收藏快捷方式  发表时间:2023-06-17, 09:01:46  
      展开↯

      #62

      作者:广西
      那这里的用户名和密码填写什么呢?

      用户名:回到我们gitee的个人页面,填写有@的名字的部分。
      密码:填写gitee密码
      文章:gitee代码通过宝塔自动同步到服务器  发表时间:2023-06-17, 08:56:50  
      展开↯

      #63

      作者:广西
      php列出目录下文件并index.html访问链接
      <?php $dir = "web"; // 替换为实际路径 $files = scandir($dir); foreach ($files as $file) { if (is_dir("$dir/$file")) { if (file_exists("$dir/$file/index.html")) { if(file_exists("/web/'.$file.'/'.$file.'.png")){ echo '<img style="width:80px;height:auto;" src="/web/'.$file.'/'.$file.'.png" />'; }else{ echo '<img style="width:80px;height:auto;" src="/web/'.$file.'/'.$file.'.gif" />'; } echo '<br><a href="/web/'.$file.'/index.html">'.$file.'</a><br>'; // header("Location: $file/index.html"); // 自动跳转到文件 } } } ?>
      Run code
      Cut to clipboard
        文章:常用命令笔记收藏快捷方式  发表时间:2023-06-17, 08:55:18  
        展开↯

        #64

        作者:广西南宁市
        将rtsp流通过ffmpeg+nginx-http-flv转成rtmp以及http-flv流,并通过flv.js在h5页面播放
        # 添加RTMP服务 rtmp { server { listen 1935; # 监听端口 chunk_size 4000; application live { live on; gop_cache on; } } } # HTTP服务 http { server { listen 80; server_name localhost; location /live { flv_live on; chunked_transfer_encoding on; #open 'Transfer-Encoding: chunked' response add_header 'Access-Control-Allow-Credentials' 'true'; #add additional HTTP header add_header 'Access-Control-Allow-Origin' '*'; #add additional HTTP header add_header Access-Control-Allow-Headers X-Requested-With; add_header Access-Control-Allow-Methods GET,POST,OPTIONS; add_header 'Cache-Control' 'no-cache'; } } }
        Run code
        Cut to clipboard

          rtsp流通过ffmpeg+nginx转成rtmp以及http-flv流
          文章:CentOS7环境配置笔记Linux  发表时间:2023-06-14, 19:19:29  
          展开↯

          #65

          作者:广西
          js获取当前日期
          JavaScript 中获得当前日期是使用
          new Date 这个内置对象的实例。 获取完整的日期(默认格式): var date = new Date(); 获取当前年份: var year = date.getFullYear(); 获取当前月份: var month = date.getMonth() + 1; 获取当前日: var day = date.getDate(); 获取当前日期(年-月-日): month = (month > 9) ? month : ("0" + month); day = (day < 10) ? ("0" + day) : day; var today = year + "-" + month + "-" + day; 另外的: date.getYear(); // 获取当前年份(2 位) date.getFullYear(); // 获取完整的年份(4 位, 1970-????) date.getMonth(); // 获取当前月份(0-11,0 代表 1 月) date.getDate(); // 获取当前日(1-31) date.getDay(); // 获取当前星期 X(0-6,0 代表星期天) date.getTime(); // 获取当前时间(从 1970.1.1 开始的毫秒数) date.getHours(); // 获取当前小时数(0-23) date.getMinutes(); // 获取当前分钟数(0-59) date.getSeconds(); // 获取当前秒数(0-59) date.getMilliseconds(); // 获取当前毫秒数(0-999) date.toLocaleDateString(); // 获取当前日期 date.toLocaleTimeString(); // 获取当前时间 date.toLocaleString( ); // 获取日期与时间
          Run code
          Cut to clipboard
            文章:数组按时间排序php,php 实现二维数组时间排序  发表时间:2023-06-01, 02:51:10  
            展开↯

            #66

            作者:广西
            php获取本月、上月时间戳的方法
            php 获取今日、昨日、上周、本月的起始时间戳和结束时间戳的方法,主要使用到了 php 的时间函数 mktime。下面首先还是直奔主题以示例说明如何使用 mktime 获取今日、昨日、上周、本月的起始时间戳和结束时间戳,然后在介绍一下 mktime 函数作用和用法。
            switch ($exchange_time) { case 1 : //本月 //本月起始时间: $begin_time = date("Y-m-d H:i:s",mktime (0,0,0, date("m"),1,date("Y"))); $end_time = date("Y-m-d H:i:s",mktime (23,59,59, date("m"),date("t"),date("Y"))); break; case 2 : //上个月(可以解决2月份Bug的问题) //上个月的起始时间: $now = new DateTime(); $now->modify('first day of last month'); $begin_time = $now->format('Y-m-01 00:00:00'); $end_time = date("Y-m-d 23:59:59", strtotime(-date('d').'day')); break; case 3 : //上上个月 $begin_time = date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m")-2,1,date("Y"))); $end_time = date("Y-m-d H:i:s",mktime(23,59,59,date("m")-1 ,0,date("Y"))); break; } echodate("Ymd",strtotime("now")),"\n"; echodate("Ymd",strtotime("-1 week Monday")),"\n"; echodate("Ymd",strtotime("-1 week Sunday")),"\n"; echodate("Ymd",strtotime("+0 week Monday")),"\n"; echodate("Ymd",strtotime("+0 week Sunday")),"\n"; echo"*********第几个月:"; echodate('n'); echo"*********本周周几:"; echodate("w"); echo"*********本月天数:"; echodate("t"); echo"*********"; echo'<br>上周起始时间:<br>'; echodate("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("w")+1-7,date("Y"))),"\n"; echodate("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+7-7,date("Y"))),"\n"; echo'<br>本周起始时间:<br>'; echodate("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("w")+1,date("Y"))),"\n"; echodate("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+7,date("Y"))),"\n"; echo'<br>上月起始时间:<br>'; echodate("Y-m-d H:i:s",mktime(0, 0 , 0,date("m")-1,1,date("Y"))),"\n"; echodate("Y-m-d H:i:s",mktime(23,59,59,date("m") ,0,date("Y"))),"\n"; echo'<br>本月起始时间:<br>'; echodate("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),1,date("Y"))),"\n"; echodate("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("t"),date("Y"))),"\n"; $season= ceil((date('n'))/3);//当月是第几季度 echo'<br>本季度起始时间:<br>'; echodate('Y-m-d H:i:s',mktime(0, 0, 0,$season*3-3+1,1,date('Y'))),"\n"; echodate('Y-m-d H:i:s',mktime(23,59,59,$season*3,date('t',mktime(0, 0 , 0,$season*3,1,date("Y"))),date('Y'))),"\n"; $season= ceil((date('n'))/3)-1;//上季度是第几季度 echo'<br>上季度起始时间:<br>'; echodate('Y-m-d H:i:s',mktime(0, 0, 0,$season*3-3+1,1,date('Y'))),"\n"; echodate('Y-m-d H:i:s',mktime(23,59,59,$season*3,date('t',mktime(0, 0 , 0,$seas))
            Run code
            Cut to clipboard
              文章:数组按时间排序php,php 实现二维数组时间排序  发表时间:2023-06-01, 02:49:19  
              展开↯

              #67

              作者:广西
              js实现数组随机排序
              function shuffle (array) { if (array.length === 0 || array.length === 1){ return array } const newArr = array.slice() let top = newArr.length while (--top) { const c = Math.floor(Math.random() * (top + 1)) const t = newArr[c] newArr[c] = newArr[top] newArr[top] = t } return newArr }
              Run code
              Cut to clipboard
                文章:js生成[n,m]的随机整数  发表时间:2023-05-31, 22:45:49  
                展开↯

                #68

                作者:广西
                PHP删除指定时间以前的文件

                PHP删除n天以前的文件,删除指定目录下指定类型(扩展名)的文件,包括子目录子和目录下的文件.
                其中$ext数组代表不删除的文件扩展名.

                调用函数trash('目录名',时间值);如trash('./files',3600)
                参数时间值的单位是秒,如果省略不写,使用trash('./'),将删除当前时间10秒前及更早的文件.

                function trash($folder,$time=10){ $ext=array('php','htm','html'); //带有这些扩展名的文件不会被删除. $o=opendir($folder); while($file=readdir($o)){ if($file !='.' && $file !='..' && !in_array(substr($file,strrpos($file,'.')+1),$ext)){ $fullPath=$folder.'/'.$file; if(is_dir($fullPath)){ trash($fullPath); @rmdir($fullPath); } else { if(time()-filemtime($fullPath) > $time){ unlink($fullPath); } } } } closedir($o); } trash('./');//调用自定义函数
                Run code
                Cut to clipboard


                  文章:nginx不浏览直接下载文件  发表时间:2023-05-31, 22:42:06  
                  展开↯

                  #69

                  作者:广西
                  微信公众平台开发 客服系统回复文本显示json_encode|unicode中文乱码


                  导致原因:在 curl post 方式调用客服接口时,
                  传参过程中使用了 json_encode 函数对变量进行 JSON 编码,我们习惯性的不填写第二个参数,
                  或者使用框架里封装好的 json 函数,导致中文乱码的问题;

                  解决方法:在 json_encode 函数加上第二个参数

                  function sendService($object, $access_token) { /* 获得openId值 */ $openid = (string)$object->FromUserName; $post_data = array( 'touser' => $openid, 'msgtype' => 'text', 'text' => array( 'content' => '这是客服自动回复的消息' ) ); $url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=" . $access_token; curlPost($url, json_encode($post_data, JSON_UNESCAPED_UNICODE)); } function curlPost($url, $post_data) { $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_URL, $url); // post数据 curl_setopt($ch, CURLOPT_POST, 1); // post的变量 curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); $response = curl_exec($ch); curl_close($ch); //-------请求为空 if(empty($response)){ exit("50001"); } return $response; }
                  Run code
                  Cut to clipboard

                    文章:PHP解决某些特殊汉字符或汉字转码后成乱码或者空白的问题  发表时间:2023-05-31, 22:40:34  
                    展开↯

                    #70

                    作者:广西
                    php给图片添加文字水印的4种方法

                    1: 面向过程的编写方法
                    //指定图片路径 $src = '001.png'; //获取图片信息 $info = getimagesize($src); //获取图片扩展名 $type = image_type_to_extension($info[2],false); //动态的把图片导入内存中 $fun = "imagecreatefrom{$type}"; $image = $fun('001.png'); //指定字体颜色 $col = imagecolorallocatealpha($image,255,255,255,50); //指定字体内容 $content = 'helloworld'; //给图片添加文字 imagestring($image,5,20,30,$content,$col); //指定输入类型 header('Content-type:'.$info['mime']); //动态的输出图片到浏览器中 $func = "image{$type}"; $func($image); //销毁图片 imagedestroy($image);
                    Run code
                    Cut to clipboard


                      2:面向对象的实现方法
                      class Image_class { private $image; private $info; /** * @param $src:图片路径 * 加载图片到内存中 */ function __construct($src){ $info = getimagesize($src); $type = image_type_to_extension($info[2],false); $this -> info =$info; $this->info['type'] = $type; $fun = "imagecreatefrom" .$type; $this -> image = $fun($src); } /** * @param $fontsize: 字体大小 * @param $x: 字体在图片中的x位置 * @param $y: 字体在图片中的y位置 * @param $color: 字体的颜色是一个包含rgba的数组 * @param $text: 想要添加的内容 * 操作内存中的图片,给图片添加文字水印 */ public function fontMark($fontsize,$x,$y,$color,$text){ $col = imagecolorallocatealpha($this->image,$color[0],$color[1],$color[2],$color[3]); imagestring($this->image,$fontsize,$x,$y,$text,$col); } /* * 输出图片到浏览器中 */ public function show(){ header('content-type:' . $this -> info['mime']); $fun='image' . $this->info['type']; $fun($this->image); } /** * 销毁图片 */ function __destruct(){ imagedestroy($this->image); } } //对类的调用 $obj = new Image_class('001.png'); $obj->fontMark(20,20,30,array(255,255,255,60),'hello'); $obj->show();
                      Run code
                      Cut to clipboard


                        3.支持以图片和文字两种方式给图片添加水印。图片支持GIF,PNG,JPG三种格式,水印图片支持PNG和GIF
                        function setWater($imgSrc,$markImg,$markText,$TextColor,$markPos,$fontType,$markType) { $srcInfo = @getimagesize($imgSrc); $srcImg_w = $srcInfo[0]; $srcImg_h = $srcInfo[1]; switch ($srcInfo[2]) { case 1: $srcim =imagecreatefromgif($imgSrc); break; case 2: $srcim =imagecreatefromjpeg($imgSrc); break; case 3: $srcim =imagecreatefrompng($imgSrc); break; default: die("不支持的图片文件类型"); exit; } if(!strcmp($markType,"img")) { if(!file_exists($markImg) || empty($markImg)) { return; } $markImgInfo = @getimagesize($markImg); $markImg_w = $markImgInfo[0]; $markImg_h = $markImgInfo[1]; if($srcImg_w < $markImg_w || $srcImg_h < $markImg_h) { return; } switch ($markImgInfo[2]) { case 1: $markim =imagecreatefromgif($markImg); break; case 2: $markim =imagecreatefromjpeg($markImg); break; case 3: $markim =imagecreatefrompng($markImg); break; default: die("不支持的水印图片文件类型"); exit; } $logow = $markImg_w; $logoh = $markImg_h; } if(!strcmp($markType,"text")) { $fontSize = 16; if(!empty($markText)) { if(!file_exists($fontType)) { return; } } else { return; } $box = @imagettfbbox($fontSize, 0, $fontType,$markText); $logow = max($box[2], $box[4]) - min($box[0], $box[6]); $logoh = max($box[1], $box[3]) - min($box[5], $box[7]); } if($markPos == 0) { $markPos = rand(1, 9); } switch($markPos) { case 1: $x = +5; $y = +5; break; case 2: $x = ($srcImg_w - $logow) / 2; $y = +5; break; case 3: $x = $srcImg_w - $logow - 5; $y = +15; break; case 4: $x = +5; $y = ($srcImg_h - $logoh) / 2; break; case 5: $x = ($srcImg_w - $logow) / 2; $y = ($srcImg_h - $logoh) / 2; break; case 6: $x = $srcImg_w - $logow - 5; $y = ($srcImg_h - $logoh) / 2; break; case 7: $x = +5; $y = $srcImg_h - $logoh - 5; break; case 8: $x = ($srcImg_w - $logow) / 2; $y = $srcImg_h - $logoh - 5; break; case 9: $x = $srcImg_w - $logow - 5; $y = $srcImg_h - $logoh -5; break; default: die("此位置不支持"); exit; } $dst_img = @imagecreatetruecolor($srcImg_w, $srcImg_h); imagecopy ( $dst_img, $srcim, 0, 0, 0, 0, $srcImg_w, $srcImg_h); if(!strcmp($markType,"img")) { imagecopy($dst_img, $markim, $x, $y, 0, 0, $logow, $logoh); imagedestroy($markim); } if(!strcmp($markType,"text")) { $rgb = explode(',', $TextColor); $color = imagecolorallocate($dst_img, $rgb[0], $rgb[1], $rgb[2]); imagettftext($dst_img, $fontSize, 0, $x, $y, $color, $fontType,$markText); } switch ($srcInfo[2]) { case 1: imagegif($dst_img, $imgSrc); break; case 2: imagejpeg($dst_img, $imgSrc); break; case 3: imagepng($dst_img, $imgSrc); break; default: die("不支持的水印图片文件类型"); exit; } imagedestroy($dst_img); imagedestroy($srcim); }
                        Run code
                        Cut to clipboard


                          参数说明:
                          $imgSrc:目标图片,可带相对目录地址, $markImg:水印图片,可带相对目录地址,支持PNG和GIF两种格式,如水印图片在执行文件mark目录下,可写成:mark/mark.gif $markText:给图片添加的水印文字 $TextColor:水印文字的字体颜色 $markPos:图片水印添加的位置,取值范围:0~9 0:随机位置,在1~8之间随机选取一个位置 1:顶部居左 2:顶部居中 3:顶部居右 4:左边居中 5:图片中心 6:右边居中 7:底部居左 8:底部居中 9:底部居右 $fontType:具体的字体库,可带相对目录地址 $markType:图片添加水印的方式,img代表以图片方式,text代表以文字方式添加水印
                          Run code
                          Cut to clipboard


                            4.给图片加文字水印的方法
                            <?php /*给图片加文字水印的方法*/ $dst_path = 'http://f4.topitme.com/4/15/11/1166351597fe111154l.jpg'; $dst = imagecreatefromstring(file_get_contents($dst_path)); /*imagecreatefromstring()--从字符串中的图像流新建一个图像,返回一个图像标示符,其表达了从给定字符串得来的图像 图像格式将自动监测,只要php支持jpeg,png,gif,wbmp,gd2.*/ $font = './t1.ttf'; $black = imagecolorallocate($dst, 0, 0, 0); imagefttext($dst, 20, 0, 10, 30, $black, $font, 'Hello world!'); /*imagefttext($img,$size,$angle,$x,$y,$color,$fontfile,$text) $img由图像创建函数返回的图像资源 size要使用的水印的字体大小 angle(角度)文字的倾斜角度,如果是0度代表文字从左往右,如果是90度代表从上往下 x,y水印文字的第一个文字的起始位置 color是水印文字的颜色 fontfile,你希望使用truetype字体的路径*/ list($dst_w,$dst_h,$dst_type) = getimagesize($dst_path); /*list(mixed $varname[,mixed $......])--把数组中的值赋给一些变量 像array()一样,这不是真正的函数,而是语言结构,List()用一步操作给一组变量进行赋值*/ /*getimagesize()能获取到什么信息? getimagesize函数会返回图像的所有信息,包括大小,类型等等*/ 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; /*imagepng--以PNG格式将图像输出到浏览器或文件 imagepng()将GD图像流(image)以png格式输出到标注输出(通常为浏览器),或者如果用filename给出了文件名则将其输出到文件*/ } imagedestroy($dst); ?>
                            Run code
                            Cut to clipboard

                              文章:nginx不浏览直接下载文件  发表时间:2023-05-31, 22:36:41  
                              展开↯

                              #71

                              作者:广西
                              <? header("Content-type: image/jpeg"); //原始图像 $dst = "images/flower_1.jpg"; //得到原始图片信息 $dst_im = imagecreatefromjpeg($dst); $dst_info = getimagesize($dst); //水印图像 $src = "images/logo.gif"; $src_im = imagecreatefromgif($src); $src_info = getimagesize($src); //水印透明度 $alpha = 30; //合并水印图片 imagecopymerge($dst_im,$src_im,$dst_info[0]-$src_info[0],$dst_info[1]-$src_info[1],0,0,$src_info[0], $src_info[1],$alpha); //输出合并后水印图片 imagejpeg($dst_im); imagedestroy($dst_im); imagedestroy($src_im); ?>
                              Run code
                              Cut to clipboard
                                #,广西,2023-05-31,22:28:27,
                                /* * 图片裁剪工具 * 将指定文件裁剪成正方形 * 以中心为起始向四周裁剪 * @param $src_path string 源文件地址 * @param $des_path string 保存文件地址 * @param $des_w double 目标图片宽度 * */ function img_cut_square($src_path,$des_path,$des_w=100){ $img_info = getimagesize($src_path);//获取原图像尺寸信息 $img_width = $img_info[0];//原图宽度 $img_height = $img_info[1];//原图高度 $img_type = $img_info[2];//图片类型 1 为 GIF 格式、 2 为 JPEG/JPG 格式、3 为 PNG 格式 if($img_type != 2 && $img_type != 3) return ; /*计算缩放尺寸*/ if($img_height > $img_width){ $scale_width = $des_w;//缩放宽度 $scale_height = round($des_w / $img_width * $img_height);//缩放高度 $src_y = round(($scale_height - $des_w)/2); $src_x = 0; }else{ $scale_height = $des_w; $scale_width = round($des_w / $img_height * $img_width); $src_y = 0; $src_x = round(($scale_width - $des_w)/2); } $dst_ims = imagecreatetruecolor($scale_width, $scale_height);//创建真彩画布 $white = imagecolorallocate($dst_ims, 255, 255, 255); imagefill($dst_ims, 0, 0, $white); if($img_type == 2){ $src_im = @imagecreatefromjpeg($src_path);//读取原图像 }else if($img_type == 3){ $src_im = @imagecreatefrompng($src_path);//读取原图像 } imagecopyresized($dst_ims, $src_im, 0, 0 ,0, 0 , $scale_width , $scale_height , $img_width,$img_height);//缩放图片到指定尺寸 $dst_im = imagecreatetruecolor($des_w, $des_w); // $white = imagecolorallocate($dst_im, 255, 255, 255); // imagefill($dst_im, 0, 0, $white); imagecopy($dst_im, $dst_ims, 0, 0, $src_x, $src_y, $des_w, $des_w);//开始裁剪图片为正方形 // imagecopyresampled($dst_im, $src_im, $src_x, $src_y, 0, 0, $real_width, $real_width,$img_width,$img_height); if($img_type == 2) { imagejpeg($dst_im, $des_path);//保存到文件 }else if($img_type == 3){ imagepng($dst_im,$des_path); } // imagejpeg($dst_im);//输出到浏览器 imagedestroy($dst_im); imagedestroy($dst_ims); imagedestroy($src_im); }
                                Run code
                                Cut to clipboard
                                  #,广西,2023-05-31,22:29:58,
                                  //1.配置图片路径 $src = "1.jpg"; //2.获取图片信息 $info = getimagesize($src); //3.通过编号获取图像类型 $type = image_type_to_extension($info[2],false); //4.在内存中创建和图像类型一样的图像 $fun = "imagecreatefrom".$type; //5.图片复制到内存 $image = $fun($src); /*操作图片*/ //1.设置字体的路径 $font = "simkai.ttf"; //2.填写水印内容 $content = "水印文字:some special words are supported."; //3.设置字体颜色和透明度 $color = imagecolorallocatealpha($image, 255, 255, 255, 0); //4.写入文字 (图片资源,字体大小,旋转角度,坐标x,坐标y,颜色,字体文件,内容) imagettftext($image, 30, 0, 100, 60, $color, $font, $content); /*输出图片*/ //浏览器输出 header("Content-type:".$info['mime']); $fun = "image".$type; $fun($image); //保存图片 $fun($image,'bg_res.'.$type); /*销毁图片*/ imagedestroy($image);
                                  Run code
                                  Cut to clipboard
                                    文章:nginx不浏览直接下载文件  发表时间:2023-05-31, 22:28:07  
                                    展开↯

                                    #72

                                    作者:广西河池市
                                    php图片的裁剪
                                    php中裁剪图片主要使用gd库的imagecopyresampled方法 $src_path = '1.jpg'; //创建源图的实例 $src = imagecreatefromstring(file_get_contents($src_path)); //裁剪开区域左上角的点的坐标 $x = 100; $y = 12; //裁剪区域的宽和高 $width = 200; $height = 200; //最终保存成图片的宽和高,和源要等比例,否则会变形 $final_width = 100; $final_height = round($final_width * $height / $width); //将裁剪区域复制到新图片上,并根据源和目标的宽高进行缩放或者拉升 $new_image = imagecreatetruecolor($final_width, $final_height); imagecopyresampled($new_image, $src, 0, 0, $x, $y, $final_width, $final_height, $width, $height); //输出图片 header('Content-Type: image/jpeg'); imagejpeg($new_image); imagedestroy($src); imagedestroy($new_image);
                                    Run code
                                    Cut to clipboard
                                      文章:nginx不浏览直接下载文件  发表时间:2023-05-31, 17:50:44  
                                      展开↯

                                      #73

                                      作者:广西河池市
                                      【PHP原生】获取字符串所有汉字首字母和首个汉字首字母
                                      获取字符串汉字首字母,兼容GBK和UTF-8
                                      <?php //获取单个汉字拼音首字母。注意:此处不要纠结。汉字拼音是没有以U和V开头的 function getfirstchar($s0){ $fchar = ord($s0{0}); if($fchar >= ord("A") and $fchar <= ord("z") )return strtoupper($s0{0}); $s1 = iconv("UTF-8","gb2312", $s0); $s2 = iconv("gb2312","UTF-8", $s1); if($s2 == $s0){$s = $s1;}else{$s = $s0;} $asc = ord($s{0}) * 256 + ord($s{1}) - 65536; if($asc >= -20319 and $asc <= -20284) return "A"; if($asc >= -20283 and $asc <= -19776) return "B"; if($asc >= -19775 and $asc <= -19219) return "C"; if($asc >= -19218 and $asc <= -18711) return "D"; if($asc >= -18710 and $asc <= -18527) return "E"; if($asc >= -18526 and $asc <= -18240) return "F"; if($asc >= -18239 and $asc <= -17923) return "G"; if($asc >= -17922 and $asc <= -17418) return "H"; if($asc >= -17922 and $asc <= -17418) return "I"; if($asc >= -17417 and $asc <= -16475) return "J"; if($asc >= -16474 and $asc <= -16213) return "K"; if($asc >= -16212 and $asc <= -15641) return "L"; if($asc >= -15640 and $asc <= -15166) return "M"; if($asc >= -15165 and $asc <= -14923) return "N"; if($asc >= -14922 and $asc <= -14915) return "O"; if($asc >= -14914 and $asc <= -14631) return "P"; if($asc >= -14630 and $asc <= -14150) return "Q"; if($asc >= -14149 and $asc <= -14091) return "R"; if($asc >= -14090 and $asc <= -13319) return "S"; if($asc >= -13318 and $asc <= -12839) return "T"; if($asc >= -12838 and $asc <= -12557) return "W"; if($asc >= -12556 and $asc <= -11848) return "X"; if($asc >= -11847 and $asc <= -11056) return "Y"; if($asc >= -11055 and $asc <= -10247) return "Z"; return NULL; //return $s0; } function pinyin_long($zh){ //获取整条字符串所有汉字拼音首字母 $ret = ""; $s1 = iconv("UTF-8","gb2312", $zh); $s2 = iconv("gb2312","UTF-8", $s1); if($s2 == $zh){$zh = $s1;} for($i = 0; $i < strlen($zh); $i++){ $s1 = substr($zh,$i,1); $p = ord($s1); if($p > 160){ $s2 = substr($zh,$i++,2); $ret .= getfirstchar($s2); }else{ $ret .= $s1; } } return $ret; } echo pinyin_long('*《,@#$123HAHadf一年后而已');echo "<br>";//console(*@#$123HAHadfYNHEY) function pinyin_long2($zh){ //获取整条字符串(非纯汉字链)首个汉字拼音首字母 $ret = ""; $s1 = iconv("UTF-8","gb2312", $zh); $s2 = iconv("gb2312","UTF-8", $s1); if($s2 == $zh){$zh = $s1;} for($i = 0; $i < strlen($zh); $i++){ $s1 = substr($zh,$i,1); $p = ord($s1); if($p > 160){ $s2 = substr($zh,$i++,2); $ret = getfirstchar($s2); }else{ $ret = $s1; } } return $ret; } echo pinyin_long2('*《,@#$123HAHadf一年后而已');//console(Y) ?>
                                      Run code
                                      Cut to clipboard
                                        文章:php获得汉字拼音首字母  发表时间:2023-05-31, 17:44:07  
                                        展开↯

                                        #74

                                        作者:广西河池市
                                        PHP前一天,后一天,日期问题
                                        date_default_timezone_set('PRC'); //默认时区 echo "今天:",date("Y-m-d",time()),"<br>"; echo "今天:",date("Y-m-d",strtotime("18 june 2008")),"<br>"; echo "昨天:",date("Y-m-d",strtotime("-1 day")), "<br>"; echo "明天:",date("Y-m-d",strtotime("+1 day")), "<br>"; echo "一周后:",date("Y-m-d",strtotime("+1 week")), "<br>"; echo "一周零两天四小时两秒后:",date("Y-m-d G:H:s",strtotime("+1 week 2 days 4 hours 2 seconds")), "<br>"; echo "下个星期四:",date("Y-m-d",strtotime("next Thursday")), "<br>"; echo "上个周一:".date("Y-m-d",strtotime("last Monday"))."<br>"; echo "一个月前:".date("Y-m-d",strtotime("last month"))."<br>"; echo "一个月后:".date("Y-m-d",strtotime("+1 month"))."<br>"; echo "十年后:".date("Y-m-d",strtotime("+10 year"))."<br>";
                                        Run code
                                        Cut to clipboard
                                          文章:js获取本周、本月、本季度、本年开始,结束时间  发表时间:2023-05-31, 17:43:27  
                                          展开↯

                                          #75

                                          作者:广西河池市
                                          php 在客户端生成txt文件并且下载

                                          在访问php时生成txt文件
                                            $filename = 'file.text'; //也可以是其他后缀格式的 $ua = $_SERVER["HTTP_USER_AGENT"]; foreach ($fedexinfo as $key => $value) { echo $key.",\"".$value."\"\r\n"; } header("Content-Type: application/octet-stream"); header('Content-Disposition: attachment; filename="' . $filename . '"');
                                          Run code
                                          Cut to clipboard

                                            文章:nginx不浏览直接下载文件  发表时间:2023-05-31, 17:42:26  
                                            展开↯

                                            #76

                                            作者:广西河池市
                                            php生成文字水印和图片水印

                                            生成文字水印
                                            //文字水印 /*打开图片*/ //1.配置图片路径 $src = "4.jpg"; //2.获取图片的信息(得到图片的基本信息) $info = getimagesize($src ); //3.通过获取图片类型 $type = image_type_to_extension($info[2],false); //4.在内存中创建一个图片类型一样的图像 $fun = "imagecreatefrom{$type}"; //5.图片复制到内存中 $image = $fun($src); /*操作图片*/ //1.设置字体的路径 $font = "STLITI.TTF";//c盘windows/fonts //2.填写水印内容 $content = '你好'; //3.设置字体的颜色rgb和透明度 $col = imagecolorallocatealpha($image,255,255,255,50); //4.写入文字 imagettftext($image,20,0,20,30,$col,$font,$content); /*输出图片*/ //浏览器输出 header("Content-type:{$info['mime']}"); $func = "image{$type}"; $func($image); //保存图片 $func($image,'newimage.'.$type); /*销毁图片*/ imagedestroy($image);
                                            Run code
                                            Cut to clipboard


                                              生成图片水印
                                              $dst_path = '4.jpg'; $src_path = '1.png'; //创建图片的实例 $dst = imagecreatefromstring(file_get_contents($dst_path)); $src = imagecreatefromstring(file_get_contents($src_path)); //获取水印图片的宽高 list($src_w, $src_h) = getimagesize($src_path); //将水印图片复制到目标图片上,最后个参数80是设置透明度,这里实现半透明效果 imagecopymerge($dst, $src, 10, 10, 0, 0, $src_w, $src_h, 80); //如果水印图片本身带透明色,则使用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);
                                              Run code
                                              Cut to clipboard


                                                #,广西河池市,2023-05-31,17:25:50, 绘制文字:imagettftext()
                                                <?php //1. 绘制图像资源(创建一个画布) $image = imagecreatetruecolor(500, 300); //2. 先分配一个绿色 $green = imagecolorallocate($image, 22, 153, 0); //3. 使用绿色填充画布 imagefill($image, 0, 0, $green); //4. 在画布中绘制图像 $bai = imagecolorallocate($image, 255, 255, 255); //使用指定的字体文件绘制文字 //参数2:字体大小 //参数3:字体倾斜的角度 //参数4、5:文字的x、y坐标 //参数6:文字的颜色 //参数7:字体文件 //参数8:绘制的文字 imagettftext($image, 30, 30, 200, 250, $bai, 'STHUPO.TTF', 'helloworld'); //5. 在浏览器直接输出图像资源 header("Content-Type:image/jpeg"); imagejpeg($image); //6. 销毁图像资源 imagedestroy($image);
                                                Run code
                                                Cut to clipboard
                                                  文章:nginx不浏览直接下载文件  发表时间:2023-05-31, 17:25:15  
                                                  展开↯
                                                  你好,残忍屏蔽广告

                                                  确定要清除编辑框内容吗?

                                                  该删除操作将不可恢复。

                                                  删除 取消

                                                  激活Windows

                                                  转到"设置"以激活Windows。