PHP中上传图片增加水印小案例

1.文档目录如上图所示。

2.前台代码:’

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
<form name='frm' method='post' action='upload.php' enctype="multipart/form-data">
        <table width="50%" border="2" align="center" rules="all" cellpadding="10">
        <tr>
            <th colspan="2">请输入信息</th>
        </tr>
        <tr>
            <th>选择上传图片</th>
            <th><input type="file" name="upload"></input></th>
        </tr>
        <tr>
            <th colspan="2"><input type="submit" name="submit" value="提交"></input></th>
        </tr>
    </table>
    </form>
</body>
</html>

php代码:

<?php
header('content-type:text/html;charset=utf-8');
if (isset($_POST['submit'])) {
    //临时文件
    $filename = $_FILES['upload']['tmp_name'];
    //目标文件路径及文件名
    $path = './upload';
    @mkdir($path);
    $destination = $path.'/'.date('YmdHis').'.jpg';
    if(move_uploaded_file($filename, $destination)){

        //水印文字开始
        $image = imagecreatefromjpeg($destination);
        //第二步
        $color = imagecolorallocatealpha($image, 200, 100, 0,mt_rand(10,100));  //0-127
        $size = 30;
        $angle = 45;
        $x = 15;
        $y = 335;
        $fontfile = './sucai/hanyi.ttf';
        $string = '制作图像文字水印效果';

        imagettftext($image, $size, $angle, $x, $y, $color, $fontfile, $string);

        //第三步,输出
        imagejpeg($image,$destination);
        //第四步,销毁
        imagedestroy($image);
        //水印文字结束
        echo "上传成功";
    }else{
        echo "上传失败";
    }
} else {
    echo "<script>alert('nono');location.href='跳转页面'</script>";
}

?>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值