zoukankan      html  css  js  c++  java
  • 在图片上添加文字水印

     1 <?php
     2     /**
     3         打开任何一种格式的图片 在图片的中间加上一个文字水印 保存
     4         只是保存下来 并不会输出到浏览器
     5     */
     6     function imagewater($filename,$string){
     7         //获得图片的属性
     8         list($width,$height,$type) = getimagesize($filename);
     9         //可以处理的照片的类型
    10         $types = array(1=>"gif",2=>"jpeg",3=>"png");
    11         //通过图片类型去组合变量函数
    12         $createfrom = "imagecreatefrom".$types[$type];
    13         //用变量函数去打开图片
    14         $image = $createfrom($filename);
    15         //设定加入文字的位置是在中间
    16         $x = ($width - imagefontwidth(5) * strlen($string)) / 2;
    17         $y = ($height - imagefontwidth(5)) / 2;
    18         //设置文字颜色
    19         $textcolor = imagecolorallocate($image,255,0,0);
    20         //将字符串画在图片上
    21         imagestring($image,5,$x,$y,$string,$textcolor);
    22         //根据图片类型组合变量函数
    23         $output = "image".$types[$type];
    24         //通过变量函数保存到原类型的图片
    25         $output($image,$filename);
    26         //$output($image);
    27         imagedestroy($image);
    28     }
    29     
    30     image("mm2.jpg","banbanban");
    31 ?>
    imagewater
  • 相关阅读:
    C sharp(C#)-小结
    安全开源工具清单
    pycharm中查看sqlite3数据库
    部署docker化的mobsf
    python处理文件、文件夹-小结
    windows上Python控制台乱码和处理
    自定义日志:记录Linux主机操作
    不是热点新闻的重大事件
    mybatis-04【小结】
    mybatis-03
  • 原文地址:https://www.cnblogs.com/banshaohuan/p/4991249.html
Copyright © 2011-2022 走看看