zoukankan      html  css  js  c++  java
  • 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;

    ?>
  • 相关阅读:
    re | [SWPU2019]ReverseMe
    wp | re | 2020“巅峰极客”网络安全技能挑战赛
    re | [CFI-CTF 2018]IntroToPE
    re | [FlareOn1]Bob Doge
    re | [ACTF新生赛2020]SoulLike
    re | [GKCTF2020]Chelly's identity
    ospf配置与ofps选举DR/BDR
    静态路由的配置
    配置三层交换机实现vlan间通信
    hybrid接口
  • 原文地址:https://www.cnblogs.com/cnn2017/p/6809607.html
Copyright © 2011-2022 走看看