【发布时间】:2016-02-02 09:42:05
【问题描述】:
我只是在 php 中做图像水印,它可以工作,但没有像我想要的那样设置图像,这是我的 php 文件代码。
<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>
<?php
if(isset($_POST['submit']))
{
// Give the Complete Path of the folder where you want to save the image
$folder="uploads/";
move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], "$folder".$_FILES["fileToUpload"]["name"]);
$file='uploads/'.$_FILES["fileToUpload"]["name"];
$uploadimage=$folder.$_FILES["fileToUpload"]["name"];
$newname=$_FILES["fileToUpload"]["name"];
// Set the thumbnail name
$thumbnail = $folder.$newname."_thumbnail.jpg";
$actual = $folder.$newname.".jpg";
$imgname=$newname."_thumbnail.jpg";
// Load the mian image
$source = imagecreatefromjpeg($uploadimage);
// load the image you want to you want to be watermarked
$watermark = imagecreatefrompng('uploads/logo1.png');
// get the width and height of the watermark image
$water_width = imagesx($watermark);
$water_height = imagesy($watermark);
// get the width and height of the main image image
$main_width = imagesx($source);
$main_height = imagesy($source);
// Set the dimension of the area you want to place your watermark we use 0
// from x-axis and 0 from y-axis
$dime_x = 0;
$dime_y = 0;
// copy both the images
imagecopy($source, $watermark, $dime_x, $dime_y, 0, 0, $water_width, $water_height);
// Final processing Creating The Image
imagejpeg($source, $thumbnail, 100);
}
?>
<img src='uploads/<?php echo $imgname;?>'>
</body>
</html>
我的 html 代码也可以正常工作。但是生成图像的问题就是这样
带有“JACLIN ADMIN”的文本是我的 png 图像,我想从上到左将它应用到中间。我只是将两者都设置为 0,但问题是当图像的大小具有不同的高度和宽度时,我怎样才能将它动态地放在中间?请帮助我。
【问题讨论】:
标签: php image-processing image-manipulation