PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

博客列表 > php 图像处理

php 图像处理

Bystander
Bystander 原创
2018年12月24日 10:54:40 1291浏览
  1. 打水印  实例

    function sy($dst_path,$src_path,$newcopy)
    {
        //创建图片的实例
        $dst = imagecreatefromstring(file_get_contents($dst_path));
        $src = imagecreatefromstring(file_get_contents($src_path));
        //获取水印图片的宽高
        list($src_w, $src_h) = getimagesize($src_path);

        //将水印图片复制到目标图片上,最后个参数50是设置透明度,这里实现半透明效果
        // imagecopymerge($dst, $src, 10, 10, 70,0, $src_w, $src_h,20);
        //如果水印图片本身带透明色,则使用imagecopy方法
        imagecopy($dst, $src, 100, 150, 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;
        // }

        // var_dump($dst);exit;
        imagejpeg($dst, $newcopy, 100); // 保存图片
    }

  2. 马赛克 实例

    function imagemask(&$im, $x1, $y1, $x2, $y2, $deep)
    {
        for($x = $x1; $x < $x2; $x += $deep){
            for ($y = $y1; $y < $y2; $y += $deep){
                $color = imagecolorat ($im, $x + round($deep / 2), $y + round($deep / 2));
                imagefilledrectangle ($im, $x, $y, $x + $deep, $y + $deep, $color);
            }
        }
    }

调用方法:

       $im = imagecreatefromjpeg($res2);  // res2 图片
        imagemask($im, 70, 30, 140, 40, 8);
        imagejpeg($im,$urlpath);   // 保存

上一条: php 方法笔记 下一条: 三大发电房
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议