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;

?>

 

转载于:https://www.cnblogs.com/cnn2017/p/6809607.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值