使用PHP上载图像时,“添加文本水印”不起作用

使用PHP上载图像时,“添加文本水印”不起作用,php,text,upload,watermark,Php,Text,Upload,Watermark,我正在开发一个php web应用程序,我想在上传多个图像时添加文本水印 addTextWatermark上传多个图像时,功能不工作或未执行?只在动态创建的文件夹上上载图像 PHP代码 function addTextWatermark($src, $watermark, $save=NULL) { list($width, $height) = getimagesize($src); $image_color = imagecreatetruecolor($width, $hei

我正在开发一个php web应用程序,我想在上传多个图像时添加文本水印

addTextWatermark
上传多个图像时,功能不工作或未执行?只在动态创建的文件夹上上载图像

PHP代码

function addTextWatermark($src, $watermark, $save=NULL) {
    list($width, $height) = getimagesize($src);
    $image_color = imagecreatetruecolor($width, $height);
    $image = imagecreatefromjpeg($src);
    imagecopyresampled($image_color, $image, 0, 0, 0, 0, $width, $height, $width, $height);
    $txtcolor = imagecolorallocate($image_color, 255, 255, 255);
    $font = 'MONOFONT.ttf';
    $font_size = 50;
    imagettftext($image_color, $font_size, 0, 50, 150, $txtcolor, $font, $watermark);
    if ($save<>'') {
        imagejpeg ($image_color, $save, 100);
    } else {
        header('Content-Type: image/jpeg');
        imagejpeg($image_color, null, 100);
    }
    imagedestroy($image);
    imagedestroy($image_color);
}



$data = explode(".", $_FILES["upload_file"]["name"]);
$extension = $data[1];
$new_file_name = rand() . '.' . $extension;
$path = $_POST["hidden_folder_name"] . '/' . $new_file_name;
foreach($_FILES['upload_file']['name'] as $key=>$val){
    $file_path = $path.$_FILES['upload_file']['name'][$key];
    $filename = $_FILES['upload_file']['name'][$key];
    if(is_uploaded_file($_FILES['upload_file']['tmp_name'][$key])) {
        if(move_uploaded_file($_FILES['upload_file']['tmp_name'][$key],$file_path)){

            $watermark = "PHPZAG"; // Add your own water mark here
            addTextWatermark($filename, $watermark, $filename);

            $upload_images[] = $file_path;
        }
    }
}
函数addTextWatermark($src,$watermark,$save=NULL){ 列表($width,$height)=getimagesize($src); $image\u color=imagecreatetruecolor($width,$height); $image=imagecreatefromjpeg($src); imagecopyresampled($image\u color,$image,0,0,0,$width,$height,$width,$height); $txtcolor=imagecolorallocate($image\u color,255,255); $font='MONOFONT.ttf'; $font_size=50; imagettftext($image\u color,$font\u size,0,50,150,$txtcolor,$font,$watermark); 如果($save“”){ 图像JPEG($image\u color,$save,100); }否则{ 标题(“内容类型:图像/jpeg”); 图像JPEG($image\u color,null,100); } 图像销毁($图像); 图像破坏($image\u color); } $data=explode(“.”,$文件[“上载文件”][“名称]); $extension=$data[1]; $new\u file\u name=rand()$扩展; $path=$\u POST[“隐藏的\u文件夹\u名称”]./”$新文件名; foreach($\u文件['upload\u文件']['name']作为$key=>$val){ $file\u path=$path.$\u FILES['upload\u file']['name'][$key]; $filename=$\u文件['upload\u file']['name'][$key]; 如果(是上传的文件($\u文件['upload\u file']['tmp\u name'][$key])){ 如果(移动上传的文件($上传文件['upload\u file']['tmp\u name'][$key],$file\u路径)){ $watermark=“PHPZAG”//在此处添加您自己的水印 addTextWatermark($filename,$watermark,$filename); $upload_images[]=$file_路径; } } }