上传到phpmyadmin时图像上的水印

时间:2017-03-30 10:33:19

标签: php mysql image phpmyadmin watermark

我正在尝试使用自动水印将图像上传到phpmyadmin。我只需上传图像,在phpmyadmin中保存图像名称(image.jpg),并将该图像保存在特定文件夹中。但是当它保存在特定的文件夹中时,我需要在图像上添加自动水印。怎么做?

上传表单和图片显示的代码:

<?php 
                          $sql = "SELECT * FROM paminklai";
                          $result = mysqli_query($connection, $sql);
                          while($row = mysqli_fetch_array($result)){
                            ?>
                        <div class="iso-box lunch col-md-4 col-sm-6">
                          <div class="gallery-thumb">
                            <a href="images/paminklai/<?php echo $row['image'] ?>" data-lightbox-gallery="food-gallery">
                              <img src="images/paminklai/<?php echo $row['image'] ?>" class="fluid-img" alt="Gallery">
                                <div class="gallery-overlay">
                                  <div class="gallery-item">
                                    <i class="fa fa-search"></i>
                                  </div>
                                </div>
                            </a>
                          </div>
                        </div>
                            <?php
                          }
                         ?>

                            <div class="iso-box lunch col-md-4 col-sm-6">
                          <div class="gallery-thumb addimg">

                               <form method="post" action="uploadimg.php" enctype="multipart/form-data">
                                <input type="hidden" name="size" value="100000">
                                <div style="margin:10px">
                                    <input id="selectedFile" type="file" onpropertychange="add()" style="position:absolute;visibility:hidden;" name="image">
                                    <input type="button" id="browseButton" value="Pasirinkti nuotrauka" onclick="selectedFile.click()">
                                </div>
                                <div>
                                    <input type="text" name="text" class="form-control" placeholder="Pavadinimas">
                                </div>
                                <div>
                                    <input type="submit" name="upload" value="Išsaugoti" style="margin:10px">
                                </div>
                            </form>
                          </div>
                        </div>

上传代码:

<?php include "config.php"; ?>
<?php
if(isset($_POST['upload'])){
    $target = "images/paminklai/".basename($_FILES['image']['name']);

    $image = strtolower($_FILES['image']['name']);
    $text = $_POST['text'];
    $sql = "INSERT INTO paminklai (image, text) VALUES ('$image', '$text')";
    mysqli_query($connection, $sql);

    if(move_uploaded_file($_FILES['image']['tmp_name'], $target)){
       header("Location: paminklaiadmin.php");
    } else {
        echo "There was a problem uploadin image";
    }
}
?>

phpmyadmin表: enter image description here

1 个答案:

答案 0 :(得分:0)

使用下面的示例脚本在图像中添加水印。

<?php
  error_reporting(0);
  if(!isset($_GET['src']) && $_GET['src']==""){  echo "provide image url in url";exit;}
  header('content-type: image/jpeg');
  $src = $_GET['src'];
  $path = pathinfo($src);
  $watermark = imagecreatefrompng('watermark.png');
  $watermark_width = imagesx($watermark);
  $watermark_height = imagesy($watermark);
  $image = imagecreatetruecolor($watermark_width, $watermark_height);
  if ($path['extension']=='png')
       $image = imagecreatefrompng($src);
  else if ($path['extension']=='jpg'||$path['extension']=='jpeg')
       $image = imagecreatefromjpeg($src);
  $size = getimagesize($_GET['src']);
  $dest_x = $size[0] - $watermark_width-200;
  $dest_y = $size[1] - $watermark_height-200;
  imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0,$watermark_width, $watermark_height, 50);
  imagejpeg($image,'image.jpg', 85);
  imagedestroy($image);
  imagedestroy($watermark);
?>