已掉线,重新登录

首页 > 绿虎论坛 > 杂类 > 超级灌水 (发帖)

标题: 测试工程费用

作者: @Ta

时间: 2023-03-29

点击: 5301

@ChatGPT,1300户楼宇对讲30000米线村,要多少费用。

[隐藏样式|查看源码]


『回复列表(14|显示机器人聊天)』

10. 学校类型是中专技校,能开什么店铺卖东西
(/@Ta/2023-04-09 23:32//)

11. 9楼的,《红色家书:传承家国情怀,铭记先烈功勋》,这名句话,我复制下来,然后发在微博评论里,秒吞,不知别人是不是这样子。
(/@Ta/2023-04-10 04:50//)

12. @坏人
(/@Ta/2023-06-06 01:51//)

20.
层主 @坏人 于 2023-10-04 10:21 删除了该楼层。
(/@Ta/2023-10-04 10:18//
被锁定
)

23. <!DOCTYPE html>
<html>
<head>
    <title>文件上传</title>
</head>
<body>
    <h1>文件上传到服务器</h1>
    <form enctype="multipart/form-data" action="/upload" method="post">
        <input type="file" name="fileToUpload" id="fileToUpload">
        <input type="submit" value="上传文件" name="submit">
    </form>

    <div id="response"></div>

    <script>
        document.querySelector('form').addEventListener('submit', function (e) {
            e.preventDefault();

            var fileInput = document.querySelector('#fileToUpload');
            var file = fileInput.files[0];

            if (file) {
                var formData = new FormData();
                formData.append('fileToUpload', file);

                var xhr = new XMLHttpRequest();
                xhr.open('POST', '1.php', true);
                xhr.onload = function () {
                    if (xhr.status === 200) {
                        document.querySelector('#response').textContent = '文件上传成功!';
                    } else {
                        document.querySelector('#response').textContent = '文件上传失败。';
                    }
                };
                xhr.send(formData);
            } else {
                alert('请选择一个文件进行上传。');
            }
        });
    </script>
</body>
</html>
,完善代码,当用户选择文件后,上传到服务
1.php
if (isset($_FILES['image'])) {  
    include ("waterImg.php");
    $uploadDir = 'images/'; // 上传目录路径,请确保该目录存在并有写入权限  
    $uploadFile = $uploadDir . uniqid() . '.jpg'; // 生成唯一的文件名,以避免重复文件名覆盖问题  
    move_uploaded_file($_FILES['image']['tmp_name'], $uploadFile); // 将临时文件移动到目标位置  
    $waterImage = 'waterImg.png'; // 水印图片路径,请确保该文件存在并有读取权限  
    imageWaterMark($uploadFile, 9, $waterImage); // 调用水印函数,9 代表水印位置,可根据需要进行调整,这里默认在右下角添加水印。请确保 include ("waterImg.php"); 语句在调用该函数之前。请提供 imageWaterMark 函数的实现或确保其在当前文件中可用。在此处,我假设 imageWaterMark 函数已经在 waterImg.php 文件中定义。如果该函数在其他文件中,请相应地修改 include 语句的路径。在调用 imageWaterMark 函数之前,请确保已经包含了定义该函数的文件。在示例代码中,我假设已经包含了 waterImg.php 文件。如果该文件不存在或未包含所需的函数定义,请创建该文件并在其中定义 imageWaterMark 函数。在示例代码中,我假设 imageWaterMark 函数接受三个参数:要添加水印的图像路径、水印位置和水印图像路径。请根据实际的函数定义和需要进行相应的调整。最后,请注意检查文件路径和目录权限,以确保上传和水印操作能够成功执行。在示例代码中,我假设
    }
(/@Ta/2023-10-04 10:27//)

38.
层主 @坏人 于 2023-10-04 11:20 删除了该楼层。
(/@Ta/2023-10-04 11:20//
被锁定
)

67. @坏人,<?php
/**
* author 张长伟
* date   2009-3-27 16:30:12
* 功能: PHP图片水印 (水印支持图片) 
* 参数: 
*      $groundImage   背景图片,即需要加水印的图片,暂只支持GIF,JPG,PNG格式; 
*      $waterPos      水印位置,有10种状态,0为随机位置; 
*                     1为顶端居左,2为顶端居中,3为顶端居右; 
*                     4为中部居左,5为中部居中,6为中部居右; 
*                     7为底端居左,8为底端居中,9为底端居右; 
*      $waterImage    图片水印,即作为水印的图片,暂只支持GIF,JPG,PNG格式; 
*      $waterText     文字水印,即把文字作为为水印,支持ASCII码,不支持中文; 
*      $textFont      文字大小,值为1、2、3、4或5,默认为5; 
*      $textColor     文字颜色,值为十六进制颜色值,默认为#FF0000(红色); 

* 注意:
*      Support GD 2.0,Support FreeType、GIF Read、GIF Create、JPG 、PNG 
*      $waterImage 和 $waterText 最好不要同时使用,选其中之一即可,优先使用 $waterImage。 
*      当$waterImage有效时,参数$waterString、$stringFont、$stringColor均不生效。 
*      加水印后的图片的文件名和 $groundImage 一样。  
*/
function imageWaterMarkWithTexts($groundImage, $waterPos = 9, $waterImage = "", $waterTexts = [])
{
    $isWaterImage = false;
    $formatMsg = "暂不支持该文件格式,请用图片处理软件将图片转换为GIF、JPG、PNG格式。";
    //读取水印文件
    if (!empty($waterImage) && file_exists($waterImage)) {
        $isWaterImage = true;
        $water_info = getimagesize($waterImage);
        $water_w = $water_info[0]; //取得水印图片的宽
        $water_h = $water_info[1]; //取得水印图片的高

        switch ($water_info[2]) //取得水印图片的格式
            {
            case 1:
                $water_im = imagecreatefromgif($waterImage);
                break;
            case 2:
                $water_im = imagecreatefromjpeg($waterImage);
                break;
            case 3:
                $water_im = imagecreatefrompng($waterImage);
                break;
            default:
                die($formatMsg);
        }
    }

    //读取背景图片
    if (!empty($groundImage) && file_exists($groundImage)) {
        $ground_info = getimagesize($groundImage);
        $ground_w = $ground_info[0]; //取得背景图片的宽
        $ground_h = $ground_info[1]; //取得背景图片的高

        switch ($ground_info[2]) //取得背景图片的格式
            {
            case 1:
                $ground_im = imagecreatefromgif($groundImage);
                break;
            case 2:
                $ground_im = imagecreatefromjpeg($groundImage);
                break;
            case 3:
                $ground_im = imagecreatefrompng($groundImage);
                break;
            default:
                die($formatMsg);
        }
    } else {
        die("需要加水印的图片不存在!");
    }

    //水印位置
    if ($isWaterImage) //图片水印
        {
        $w = $water_w;
        $h = $water_h;
        $label = "图片的";
    } else //文字水印
    {
        $temp = imagettfbbox(ceil($textFont * 3), 0, "ttff.ttf", $waterText); //取得使用 TrueType 字体的文本的范围
        $w = $temp[2] - $temp[6];
        $h = $temp[3] - $temp[7];
        unset($temp);
        $label = "文字区域";
    }
    //判断图片大小与水印大小
    //if( ($ground_w<$w) || ($ground_h<$h) )
    // {
    //  echo "需要加水印的图片的长度或宽度比水印".$label."还小,无法生成水印!";
    //  return;
    // }
    switch ($waterPos) {
        case 0: //随机
            $posX = rand(0, ($ground_w - $w));
            $posY = rand(0, ($ground_h - $h));
            break;
        case 1: //1为顶端居左
            $posX = 0;
            $posY = 0;
            break;
        case 2: //2为顶端居中
            $posX = ($ground_w - $w) / 2;
            $posY = 0;
            break;
        case 3: //3为顶端居右
            $posX = $ground_w - $w;
            $posY = 0;
            break;
        case 4: //4为中部居左
            $posX = 0;
            $posY = ($ground_h - $h) / 2;
            break;
        case 5: //5为中部居中
            $posX = ($ground_w - $w) / 2;
            $posY = ($ground_h - $h) / 2;
            break;
        case 6: //6为中部居右
            $posX = $ground_w - $w;
            $posY = ($ground_h - $h) / 2;
            break;
        case 7: //7为底端居左
            $posX = 0;
            $posY = $ground_h - $h;
            break;
        case 8: //8为底端居中
            $posX = ($ground_w - $w) / 2;
            $posY = $ground_h - $h;
            break;
        case 9: //9为底端居右
            $posX = $ground_w - $w;
            $posY = $ground_h - $h;
            break;
        default: //随机
            $posX = rand(0, ($ground_w - $w));
            $posY = rand(0, ($ground_h - $h));
            break;
    }

    //设定图像的混色模式
    imagealphablending($ground_im, true);
    //解决变黑色问题
    $resize_im = imagecreatetruecolor($water_w, $water_h);
    // 下面三行是重点,解决png、gif透明背景变黑色的问题
    imagesavealpha($ground_im, true);
    imagealphablending($resize_im, false); //不合并颜色,直接用$im图像颜色替换,包括透明色;
    imagesavealpha($resize_im, true); //不要丢了$resize_im图像的透明色;


    if ($isWaterImage) {
        imagecopy($ground_im, $water_im, $posX, $posY, 0, 0, $water_w, $water_h); //拷贝水印到目标文件
    } else {
        //遍历文本水印并将它们添加到图像
        foreach ($waterTexts as $waterTextInfo) {
            list($textX, $textY, $fontSize, $text, $textColor, $shadowColor) = $waterTextInfo;

            // 添加阴影效果
            $shadow = imagecolorallocate($ground_im, hexdec(substr($shadowColor, 1, 2)), hexdec(substr($shadowColor, 3, 2)), hexdec(substr($shadowColor, 5)));
            imagettftext($ground_im, $fontSize, 0, $textX + 2, $textY + 2, $shadow, "cour.ttf", $text);

            // 添加实际文本
            list($R, $G, $B) = sscanf($textColor, "#%02x%02x%02x");
            $textColorRGB = imagecolorallocate($ground_im, $R, $G, $B);
            imagettftext($ground_im, $fontSize, 0, $textX, $textY, $textColorRGB, "cour.ttf", $text);
        }
    }

    //生成水印后的图片
    @unlink($groundImage);
    switch ($ground_info[2]) {
        case 1:
            imagegif($ground_im, $groundImage);
            break;
        case 2:
            imagejpeg($ground_im, $groundImage);
            break;
        case 3:
            imagepng($ground_im, $groundImage);
            break;
        default:
            die($errorMsg);
    }

    //释放内存
    if (isset($water_info))
        unset($water_info);
    if (isset($water_im))
        imagedestroy($water_im);
    unset($ground_info);
    imagedestroy($ground_im);
}
//然后,您可以使用中文文字水印信息数组,如下所示:

$uploadfile = "images/651f8316b3e95.jpg"; //图片存放的路径

// 定义一个文本水印信息的数组,包含中文水印
$waterTexts = [
    [10, 10, 5, "第一文字背景颜色天空蓝", "#FFFFFF", "#000000"], // X, Y, 字体大小, 文本, 文本颜色, 阴影颜色
    [10, 40, 3, date("Y-m-d H:i:s"), "#FFFFFF", "#000000"], // X, Y, 字体大小, 文本(系统时间), 文本颜色, 阴影颜色
    [10, 70, 3, "经纬度信息", "#FFFFFF", "#000000"], // X, Y, 字体大小, 文本(纬度/经度), 文本颜色, 阴影颜色
    [10, 100, 3, "位置名称", "#FFFFFF", "#000000"], // X, Y, 字体大小, 文本(位置名称), 文本颜色, 阴影颜色
    [10, 130, 3, "备注信息", "#FFFFFF", "#000000"], // X, Y, 字体大小, 文本(备注),文本颜色, 阴影颜色
    [10, 160, 3, "中文水印测试", "#FFFFFF", "#000000"], // 添加中文水印,X, Y, 字体大小, 中文文本, 文本颜色, 阴影颜色
];

imageWaterMarkWithTexts($uploadfile, 9, "", $waterTexts);
echo "<img src=\"" . $uploadfile . "\" border=\"0\">";

?>
Warning: imagecreatetruecolor(): Invalid image dimensions in /www/wwwroot/88.162118.cn/waterImg.php on line 144

Warning: imagealphablending() expects parameter 1 to be resource, boolean given in /www/wwwroot/88.162118.cn/waterImg.php on line 147

Warning: imagesavealpha() expects parameter 1 to be resource, boolean given in /www/wwwroot/88.162118.cn/waterImg.php on line 148

Warning: imagettftext(): Could not find/open font in /www/wwwroot/88.162118.cn/waterImg.php on line 160

Warning: imagettftext(): Could not find/open font in /www/wwwroot/88.162118.cn/waterImg.php on line 165

Warning: imagettftext(): Could not find/open font in /www/wwwroot/88.162118.cn/waterImg.php on line 160

Warning: imagettftext(): Could not find/open font in /www/wwwroot/88.162118.cn/waterImg.php on line 165

Warning: imagettftext(): Could not find/open font in /www/wwwroot/88.162118.cn/waterImg.php on line 160

Warning: imagettftext(): Could not find/open font in /www/wwwroot/88.162118.cn/waterImg.php on line 165

Warning: imagettftext(): Could not find/open font in /www/wwwroot/88.162118.cn/waterImg.php on line 160

Warning: imagettftext(): Could not find/open font in /www/wwwroot/88.162118.cn/waterImg.php on line 165

Warning: imagettftext(): Could not find/open font in /www/wwwroot/88.162118.cn/waterImg.php on line 160

Warning: imagettftext(): Could not find/open font in /www/wwwroot/88.162118.cn/waterImg.php on line 165

Warning: imagettftext(): Could not find/open font in /www/wwwroot/88.162118.cn/waterImg.php on line 160

Warning: imagettftext(): Could not find/open font in /www/wwwroot/88.162118.cn/waterImg.php on line 165
出错了,修改后的代码发出来用中文回复;
(/@Ta/2023-10-06 12:06//)

110. <?php
/*
* author 张长伟
* date   2009-3-27 16:30:12
* 功能: PHP图片水印 (水印支持图片) 
* 参数: 
*      $groundImage   背景图片,即需要加水印的图片,暂只支持GIF,JPG,PNG格式; 
*      $waterPos      水印位置,有10种状态,0为随机位置; 
*                     1为顶端居左,2为顶端居中,3为顶端居右; 
*                     4为中部居左,5为中部居中,6为中部居右; 
*                     7为底端居左,8为底端居中,9为底端居右; 
*      $waterImage    图片水印,即作为水印的图片,暂只支持GIF,JPG,PNG格式; 
*      $waterText     文字水印,即把文字作为为水印,支持ASCII码,不支持中文; 
*      $textFont      文字大小,值为1、2、3、4或5,默认为5; 
*      $textColor     文字颜色,值为十六进制颜色值,默认为#FF0000(红色); 

* 注意:
*      Support GD 2.0,Support FreeType、GIF Read、GIF Create、JPG 、PNG 
*      $waterImage 和 $waterText 最好不要同时使用,选其中之一即可,优先使用 $waterImage。 
*      当$waterImage有效时,参数$waterString、$stringFont、$stringColor均不生效。 
*      加水印后的图片的文件名和 $groundImage 一样。  
*/
function imageWaterMark($groundImage, $waterPos = 9, $waterImage = "", $waterText =
    "", $textFont = 1, $textColor = "#FF0000")
{
    $isWaterImage = false;
    $formatMsg = "暂不支持该文件格式,请用图片处理软件将图片转换为GIF、JPG、PNG格式。";
    //读取水印文件
    if (!empty($waterImage) && file_exists($waterImage)) {
        $isWaterImage = true;
        $water_info = getimagesize($waterImage);
        $water_w = $water_info[0]; //取得水印图片的宽
        $water_h = $water_info[1]; //取得水印图片的高
        switch ($water_info[2]) //取得水印图片的格式
            {
            case 1:
                $water_im = imagecreatefromgif($waterImage);
                break;
            case 2:
                $water_im = imagecreatefromjpeg($waterImage);
                break;
            case 3:
                $water_im = imagecreatefrompng($waterImage);
                break;
            default:
                die($formatMsg);
        }
    }
    //读取背景图片
    if (!empty($groundImage) && file_exists($groundImage)) {
        $ground_info = getimagesize($groundImage);
        $ground_w = $ground_info[0]; //取得背景图片的宽
        $ground_h = $ground_info[1]; //取得背景图片的高
        switch ($ground_info[2]) //取得背景图片的格式
            {
            case 1:
                $ground_im = imagecreatefromgif($groundImage);
                break;
            case 2:
                $ground_im = imagecreatefromjpeg($groundImage);
                break;
            case 3:
                $ground_im = imagecreatefrompng($groundImage);
                break;
            default:
                die($formatMsg);
        }
    } else {
        die("需要加水印的图片不存在!");
    }
    //水印位置
    if ($isWaterImage) //图片水印
        {
        $w = $water_w;
        $h = $water_h;
        $label = "图片的";
    } else //文字水印
    {
        $temp = imagettfbbox(ceil($textFont * 3), 0, "ttff.ttf", $waterText); //取得使用 TrueType 字体的文本的范围
        $w = $temp[2] - $temp[6];
        $h = $temp[3] - $temp[7];
        unset($temp);
        $label = "文字区域";
    }
    //判断图片大小与水印大小
    //if( ($ground_w<$w) || ($ground_h<$h) )
    // {
    //  echo "需要加水印的图片的长度或宽度比水印".$label."还小,无法生成水印!";
    //  return;
    // }
    switch ($waterPos) {
        case 0: //随机
            $posX = rand(0, ($ground_w - $w));
            $posY = rand(0, ($ground_h - $h));
            break;
        case 1: //1为顶端居左
            $posX = 0;
            $posY = 0;
            break;
        case 2: //2为顶端居中
            $posX = ($ground_w - $w) / 2;
            $posY = 0;
            break;
        case 3: //3为顶端居右
            $posX = $ground_w - $w;
            $posY = 0;
            break;
        case 4: //4为中部居左
            $posX = 0;
            $posY = ($ground_h - $h) / 2;
            break;
        case 5: //5为中部居中
            $posX = ($ground_w - $w) / 2;
            $posY = ($ground_h - $h) / 2;
            break;
        case 6: //6为中部居右
            $posX = $ground_w - $w;
            $posY = ($ground_h - $h) / 2;
            break;
        case 7: //7为底端居左
            $posX = 0;
            $posY = $ground_h - $h;
            break;
        case 8: //8为底端居中
            $posX = ($ground_w - $w) / 2;
            $posY = $ground_h - $h;
            break;
        case 9: //9为底端居右
            $posX = $ground_w - $w;
            $posY = $ground_h - $h;
            break;
        default: //随机
            $posX = rand(0, ($ground_w - $w));
            $posY = rand(0, ($ground_h - $h));
            break;
    }
    //设定图像的混色模式
    imagealphablending($ground_im, true);
    //解决变黑色问题
    $resize_im = imagecreatetruecolor($water_w, $water_h);
    // 下面三行是重点,解决png、gif透明背景变黑色的问题
    imagesavealpha($ground_im, true);
    imagealphablending($resize_im, false); //不合并颜色,直接用$im图像颜色替换,包括透明色;
    imagesavealpha($resize_im, true); //不要丢了$resize_im图像的透明色;
    if ($isWaterImage) //图片水印
        {
        imagecopy($ground_im, $water_im, $posX, $posY, 0, 0, $water_w, $water_h); //拷贝水印到目标文件
    } else //文字水印
    {
        if (!empty($textColor) && (strlen($textColor) == 7)) {
            $R = hexdec(substr($textColor, 1, 2));
            $G = hexdec(substr($textColor, 3, 2));
            $B = hexdec(substr($textColor, 5));
        } else {
            die("水印文字颜色格式不正确!");
        }
        imagestring($ground_im, $textFont, $posX, $posY, $waterText, imagecolorallocate
            ($ground_im, $R, $G, $B));
    }
    //生成水印后的图片
    @unlink($groundImage);
    switch ($ground_info[2]) //取得背景图片的格式
        {
        case 1:
            imagegif($ground_im, $groundImage);
            break;
        case 2:
            imagejpeg($ground_im, $groundImage);
            break;
        case 3:
            imagepng($ground_im, $groundImage);
            break;
        default:
            die($errorMsg);
    }
    //释放内存
    if (isset($water_info))
        unset($water_info);
    if (isset($water_im))
        imagedestroy($water_im);
    unset($ground_info);
    imagedestroy($ground_im);
}
//---------------------------------------------------------------------------------------
error_reporting(E_ALL);
ini_set('display_errors', '1');
// 在这之后执行您的代码
$uploadfile = "images/651fa047ccf0c.jpg"; // 图片存放的路径
$waterImage = ""; // 水印图片路径
// 第一条文字水印
imageWaterMark($uploadfile, 9, $waterImage, "水印1", 3, "#FF0000");
echo "<img src=\"" . $uploadfile . "\" border=\"0\">";
?>可是错误还在
Notice: Undefined variable: water_w in /www/wwwroot/88.162118.cn/1.php on line 140

Notice: Undefined variable: water_h in /www/wwwroot/88.162118.cn/1.php on line 140
(/@Ta/2023-10-06 22:29//)

127. 函数中字体文件路径是 "ttff.ttf"是正确的已经试过可以用
(/@Ta/2023-10-06 23:06//)

134. @坏人,先把图片水印个代码全部先删了只保留文字水印写入的相关代码.<?php
/*
* author 张长伟
* date   2009-3-27 16:30:12
* 功能: PHP图片水印 (水印支持图片) 
* 参数: 
*      $groundImage   背景图片,即需要加水印的图片,暂只支持GIF,JPG,PNG格式; 
*      $waterPos      水印位置,有10种状态,0为随机位置; 
*                     1为顶端居左,2为顶端居中,3为顶端居右; 
*                     4为中部居左,5为中部居中,6为中部居右; 
*                     7为底端居左,8为底端居中,9为底端居右; 
*      $waterImage    图片水印,即作为水印的图片,暂只支持GIF,JPG,PNG格式; 
*      $waterText     文字水印,即把文字作为为水印,支持ASCII码,不支持中文; 
*      $textFont      文字大小,值为1、2、3、4或5,默认为5; 
*      $textColor     文字颜色,值为十六进制颜色值,默认为#FF0000(红色); 

* 注意:
*      Support GD 2.0,Support FreeType、GIF Read、GIF Create、JPG 、PNG 
*      $waterImage 和 $waterText 最好不要同时使用,选其中之一即可,优先使用 $waterImage。 
*      当$waterImage有效时,参数$waterString、$stringFont、$stringColor均不生效。 
*      加水印后的图片的文件名和 $groundImage 一样。  
*/
function imageWaterMark($groundImage, $waterPos = 9, $waterImage = "", $waterText =
    "", $textFont = 1, $textColor = "#FF0000")
{
    $isWaterImage = false;
    $formatMsg = "暂不支持该文件格式,请用图片处理软件将图片转换为GIF、JPG、PNG格式。";
    //读取水印文件
    if (!empty($waterImage) && file_exists($waterImage)) {
        $isWaterImage = true;
        $water_info = getimagesize($waterImage);
        $water_w = $water_info[0]; //取得水印图片的宽
        $water_h = $water_info[1]; //取得水印图片的高
        switch ($water_info[2]) //取得水印图片的格式
            {
            case 1:
                $water_im = imagecreatefromgif($waterImage);
                break;
            case 2:
                $water_im = imagecreatefromjpeg($waterImage);
                break;
            case 3:
                $water_im = imagecreatefrompng($waterImage);
                break;
            default:
                die($formatMsg);
        }
    }
    //读取背景图片
    if (!empty($groundImage) && file_exists($groundImage)) {
        $ground_info = getimagesize($groundImage);
        $ground_w = $ground_info[0]; //取得背景图片的宽
        $ground_h = $ground_info[1]; //取得背景图片的高
        switch ($ground_info[2]) //取得背景图片的格式
            {
            case 1:
                $ground_im = imagecreatefromgif($groundImage);
                break;
            case 2:
                $ground_im = imagecreatefromjpeg($groundImage);
                break;
            case 3:
                $ground_im = imagecreatefrompng($groundImage);
                break;
            default:
                die($formatMsg);
        }
    } else {
        die("需要加水印的图片不存在!");
    }
    $water_w = 0; // 初始化水印宽度
    $water_h = 0; // 初始化水印高度
    //水印位置
    if ($isWaterImage) //图片水印
        {
        $water_w = $water_info[0];
        $water_h = $water_info[1];
        $w = $water_w;
        $h = $water_h;
        $label = "图片的";
    } else //文字水印
    {
        $temp = imagettfbbox(ceil($textFont * 3), 0, "ttff.ttf", $waterText); //取得使用 TrueType 字体的文本的范围
        $w = $temp[2] - $temp[6];
        $h = $temp[3] - $temp[7];
        unset($temp);
        $label = "文字区域";
    }
    //判断图片大小与水印大小
    //if( ($ground_w<$w) || ($ground_h<$h) )
    // {
    //  echo "需要加水印的图片的长度或宽度比水印".$label."还小,无法生成水印!";
    //  return;
    // }
    switch ($waterPos) {
        case 0: //随机
            $posX = rand(0, ($ground_w - $w));
            $posY = rand(0, ($ground_h - $h));
            break;
        case 1: //1为顶端居左
            $posX = 0;
            $posY = 0;
            break;
        case 2: //2为顶端居中
            $posX = ($ground_w - $w) / 2;
            $posY = 0;
            break;
        case 3: //3为顶端居右
            $posX = $ground_w - $w;
            $posY = 0;
            break;
        case 4: //4为中部居左
            $posX = 0;
            $posY = ($ground_h - $h) / 2;
            break;
        case 5: //5为中部居中
            $posX = ($ground_w - $w) / 2;
            $posY = ($ground_h - $h) / 2;
            break;
        case 6: //6为中部居右
            $posX = $ground_w - $w;
            $posY = ($ground_h - $h) / 2;
            break;
        case 7: //7为底端居左
            $posX = 0;
            $posY = $ground_h - $h;
            break;
        case 8: //8为底端居中
            $posX = ($ground_w - $w) / 2;
            $posY = $ground_h - $h;
            break;
        case 9: //9为底端居右
            $posX = $ground_w - $w;
            $posY = $ground_h - $h;
            break;
        default: //随机
            $posX = rand(0, ($ground_w - $w));
            $posY = rand(0, ($ground_h - $h));
            break;
    }
    //设定图像的混色模式
    imagealphablending($ground_im, true);
    // 解决变黑色问题(仅在有图片水印时执行)
    if ($isWaterImage) {
        //解决变黑色问题
        $resize_im = imagecreatetruecolor($water_w, $water_h);
        // 下面三行是重点,解决png、gif透明背景变黑色的问题
        imagesavealpha($ground_im, true);
        imagealphablending($resize_im, false); //不合并颜色,直接用$im图像颜色替换,包括透明色;
        imagesavealpha($resize_im, true); //不要丢了$resize_im图像的透明色;
    }
    if ($isWaterImage) //图片水印
        {
        imagecopy($ground_im, $water_im, $posX, $posY, 0, 0, $water_w, $water_h); //拷贝水印到目标文件
    } else //文字水印
    {
        if (!empty($textColor) && (strlen($textColor) == 7)) {
            $R = hexdec(substr($textColor, 1, 2));
            $G = hexdec(substr($textColor, 3, 2));
            $B = hexdec(substr($textColor, 5));
        } else {
            die("水印文字颜色格式不正确!");
        }
        imagestring($ground_im, $textFont, $posX, $posY, $waterText, imagecolorallocate
            ($ground_im, $R, $G, $B));

        // 将文字水印写入图像
        imagestring($ground_im, 20, 20, 50, "eeeeeeeeeeeeeeee", imagecolorallocate($ground_im,255, 0, 0));

    }
    //生成水印后的图片
    @unlink($groundImage);
    switch ($ground_info[2]) //取得背景图片的格式
        {
        case 1:
            imagegif($ground_im, $groundImage);
            break;
        case 2:
            imagejpeg($ground_im, $groundImage);
            break;
        case 3:
            imagepng($ground_im, $groundImage);
            break;
        default:
            die($errorMsg);
    }
    //释放内存
    if (isset($water_info))
        unset($water_info);
    if (isset($water_im))
        imagedestroy($water_im);
    unset($ground_info);
    imagedestroy($ground_im);
}
//---------------------------------------------------------------------------------------
error_reporting(E_ALL);
ini_set('display_errors', '1');
// 在这之后执行您的代码
$uploadfile = "images/651fa047ccf0c.jpg"; // 图片存放的路径
$waterImage = ""; // 水印图片路径
// 第一条文字水印
$waterText = "Hello你的水印文本"; // 你的水印文本
$asciiText = '';

for ($i = 0; $i < strlen($waterText); $i++) {
    $asciiText .= ord($waterText[$i]) . ' ';
}

echo $asciiText;
imageWaterMark($uploadfile, 5, $waterImage, $asciiText, "5",
    "#46FB04");
echo "<img src=\"" . $uploadfile . "\" border=\"0\">";
?>
<?php
/**
 * // 创建一个背景图像
 * $width = 400;
 * $height = 200;
 * $image = imagecreatetruecolor($width, $height);

 * // 定义颜色
 * $bgColor = imagecolorallocate($image, 255, 255, 255); // 背景颜色为白色
 * $textColor = imagecolorallocate($image, 255, 0, 0); // 文字颜色为红色

 * // 填充背景色
 * imagefill($image, 0, 0, $bgColor);

 * // 文字水印内容
 * $watermarkText = "Watermark";

 * // 字体文件路径
 * $fontFile = "ttff.ttf"; // 请确保此文件存在于脚本所在目录或指定路径中

 * // 字体大小
 * $fontSize = 20;

 * // 水印位置
 * $watermarkX = 20;
 * $watermarkY = 50;

 * // 将文字水印写入图像
 * imagestring($image, 20, 20, 50, "eeeeeeeeeeeeeeee", imagecolorallocate($image, 255, 0, 0));
imagestring($image, $fontSize, $watermarkX, $watermarkY, $watermarkText, $textColor);

 * // 输出图像
 * header("Content-type: image/png");
 * imagepng($image);

 * // 释放图像资源
 * imagedestroy($image);
 */
?>
(/@Ta/2023-10-06 23:16//)

173. @坏人, 在处理的图片大小是711 × 400 px的时候字体行间隔不会相对缩小
(/@Ta/2023-10-07 11:03//)

180. @坏人,计算X坐标你无计算
(/@Ta/2023-10-07 11:22//)

193. <!DOCTYPE html>
<html>
<head>
    <title>文件上传</title>
</head>
<body>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <h1>选择图片并自动上传到服务器</h1>
    <form enctype="multipart/form-data" action="/upload" method="post">
        <input type="file" accept="image/*" capture="camera" name="fileToUpload" id="fileToUpload">
        <select name="project" id="project">
            <option value="project1">项目1</option>
            <option value="project2">项目2</option>
            <option value="project3">项目3</option>
        </select>
        <input type="text" name="comments" id="comments" placeholder="备注">
        <input type="hidden" name="latitude" id="latitude" value="">
        <input type="hidden" name="longitude" id="longitude" value="">
    </form>

    <div id="response"></div>

    <script>
        document.querySelector('#fileToUpload').addEventListener('change', function () {
            var fileInput = document.querySelector('#fileToUpload');
            var file = fileInput.files[0];

            if (file) {
                var formData = new FormData();
                formData.append('fileToUpload', file);
                formData.append('project', document.querySelector('#project').value);
                formData.append('comments', document.querySelector('#comments').value);

                // 获取用户的经纬度数据(假设通过某种方式获取到了)
                var latitude = 123.456; // 用实际数据替换
                var longitude = 78.910; // 用实际数据替换
                formData.append('latitude', latitude);
                formData.append('longitude', longitude);

                var xhr = new XMLHttpRequest();
                xhr.open('POST', '1.php', true);
                xhr.onload = function () {
                    if (xhr.status === 200) {
                        // 服务器返回处理后的图像路径
                        var imagePath = xhr.responseText;
                        
                        // 更新页面以显示处理后的图像
                        var responseDiv = document.querySelector('#response');
                        responseDiv.innerHTML = '<h2>处理后的图像</h2><img src="' + imagePath + '" alt="处理后的图像" width="500">';
                    } else {
                        // 显示错误消息
                        var responseDiv = document.querySelector('#response');
                        responseDiv.textContent = '文件上传失败。';
                    }
                };
                xhr.send(formData);
            } else {
                alert('请选择一个文件进行上传。');
            }
        });
    </script>
</body>
</html>用浏览器获取用户的经纬度数据,第一次打开网页就请求取得授权同意后才能使用
(/@Ta/2023-10-07 12:01//)

312. 加入处理'无EXIF信息的图片'的方法
(/@Ta/2023-10-17 20:49//)

回复需要登录

7月14日 23:45 星期一

本站由hu60wap6驱动

备案号: 京ICP备18041936号-1