如何解决php水印错误无法复制图像或放置水印
经过长时间的剪切代码并将其放置在我自己的多文件上传器代码中的相应位置后,我遇到了一个错误,据我所知没有任何原因,下面的代码就是我正在使用的
<?php
ini_set("error_reporting",1);
if(isset($_POST['btnSubmit']))
{
for ($i = 0; $i < count($_FILES['files']['name']); $i++)
{
if ($_FILES["files"]["size"][$i] < 1000000000) // Check File size (Allow 1000MB)
{
$temp = $_FILES["files"]["tmp_name"][$i];
$name = $_FILES["files"]["name"][$i];
$targetFilePath = 'images/thumbs/'.$name;
$watermarkImagePath = 'watermark.png';
$statusMsg = '';
if(move_uploaded_file($_FILES["file"]["tmp_name"][$i],$targetFilePath)){
// Load the stamp and the photo to apply the watermark to
$watermarkImg = imagecreatefrompng($watermarkImagePath);
switch($fileType){
case 'jpg':
$im = imagecreatefromjpeg($targetFilePath);
break;
case 'jpeg':
$im = imagecreatefromjpeg($targetFilePath);
break;
case 'png':
$im = imagecreatefrompng($targetFilePath);
break;
default:
$im = imagecreatefromjpeg($targetFilePath);
}
}
// Set the margins for the watermark
$marge_right = 10;
$marge_bottom = 10;
// Get the height/width of the watermark image
$sx = imagesx($watermarkImg);
$sy = imagesy($watermarkImg);
// Copy the watermark image onto our photo using the margin offsets and
// the photo width to calculate the positioning of the watermark.
imagecopy($im,$watermarkImg,imagesx($im) - $sx - $marge_right,imagesy($im) - $sy - $marge_bottom,imagesx($watermarkImg),imagesy($watermarkImg))>debug.log;
// Save image and free memory
imagepng($im,$targetFilePath);
$old = $targetFilePath;
$new = "images/fulls/".$name;
echo '<br/>img:'.$im.' <br/>target:'.$targetFilePath.' <br/>name:'.$name.' <br/>old:'.$old.' <br/>new:'.$new.'<br/>';
copy($old,$new) or die("Unable to copy $old to $new.");
imagedestroy($im);
if(file_exists($targetFilePath)){
$statusMsg = "The image with watermark has been uploaded successfully.";
}else{
$statusMsg = "Image upload failed,please try again.";
}
// Display status message
echo $statusMsg;
if(empty($temp))
{
break;
}
if($i == 0){ $err = "<span style='color:lime;'>Files uploaded successfully</span>"; $cls = "success"; }
//move_uploaded_file($temp,"images/thumbs/".$name);
//$old = "images/thumbs/".$name;
//$new = "images/fulls/".$name;
//copy($old,$new) or die("Unable to copy $old to $new.");
}
else
{
$err = "File size is more than 1000MB";
$cls = "danger";
}
}
}
?>
表单和 html 是广泛但可操作的,所以我不会包括 php 是错误的来源,我认为我的代码拼接 womehwere 有问题,但返回的是没有我的水印的图像或 {{1 }} 复制片段中的错误返回 or die
希望这是一个愚蠢的简单修复,但据我所知,我不确定我做错了什么
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。