• php原生带码给图片添加水印及缩略图


    水印

    <?php
    // 水印
        $dst_path = 'http://www.yii.com/curl/img/144.gif';//图片路径
    
        //创建图片的实例
        $dst = imagecreatefromstring(file_get_contents($dst_path));
    
        //打上文字
        $font = './ziti.ttf';//字体(必须下载字体库)
        $black = imagecolorallocate($dst, 0x00, 0x00, 0x00);//字体颜色
        imagefttext($dst, 13, 0, 20, 20, $black, $font, 'ddddddddddddd');
    
        //输出图片
        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);
    ?>

    缩略图

    <?php
    // 缩略图 function img_create_small($big_img, $width, $height, $small_img) //原始大图地址,缩略图宽度,高度,缩略图地址 { $imgage = getimagesize($big_img); //得到原始大图片 switch ($imgage[2]) { // 图像类型判断 case 1: $im = imagecreatefromgif($big_img); break; case 2: $im = imagecreatefromjpeg($big_img); break; case 3: $im = imagecreatefrompng($big_img); break; } $src_W = $imgage[0]; //获取大图片宽度 $src_H = $imgage[1]; //获取大图片高度 $tn = imagecreatetruecolor($width, $height); //创建缩略图 imagecopyresampled($tn, $im, 0, 0, 0, 0, $width, $height, $src_W, $src_H); //复制图像并改变大小 imagejpeg($tn, $small_img); //输出图像 } $su=img_create_small('http://www.yii.com/curl/img/141.jpg','100','100','./img/aa.gif'); echo $su;

    ?>
  • 相关阅读:
    Git修改用户名和提交的邮箱
    在vue项目中引入bootstrap
    自定义radio,使用图片进行切换(点击切换时,获取变量值)
    nodejs知识清单
    swoft源码研究
    Nginx变量查询
    mongodb索引
    mongodb数据备份:导入导出
    mongodb主从复制和分片
    mongodb服务安装
  • 原文地址:https://www.cnblogs.com/cnn2017/p/6809607.html
Copyright © 2020-2023  润新知