0
我现在有一些直接上传图片到从我的服务器我的S3存储一个全功能的脚本...PHP亚马逊S3与水印上传
不过,我想现在开始添加水印到每一个上传图片。如你所知,上传到S3永远不会真正将它存储在服务器上,就像临时文件一样。
基本上,我想上传一个图像到S3(已经工作),但之前,我想为该图像添加一个水印(不工作)。
这里是工作的代码THATS文件上载TO MY S3 BUCKET:
if (!class_exists('S3'))require_once('S3.php');
//AWS access info
if (!defined('awsAccessKey')) define('awsAccessKey', 'BLAHBLAH');
if (!defined('awsSecretKey')) define('awsSecretKey', 'BLAHBLAH');
//instantiate the class
$s3 = new S3(awsAccessKey, awsSecretKey);
$fileName = $_FILES['theFile']['name'];
$fileTempName = $_FILES['theFile']['tmp_name'];
$fileSize = $_FILES['theFile']['size'];
$fileExt = substr($fileName, strrpos($fileName, '.') + 1);
$fileExt = strtolower($fileExt);
$custompostid = rand(1000000,9999999);
$imageName = $custompostid.".".$fileExt."";
//move the file
if ($s3->putObjectFile($fileTempName, "BUCKETNAME", $image, S3::ACL_PUBLIC_READ, array(), $imageType)) {
//success
}
else{
//error
}
但在此之前上传文件,我要添加水印每个图像。有此功能:
// getting the image name from GET variable
$image = $_GET['image'];
// creating png image of watermark
$watermark = imagecreatefrompng('watermark.png');
// getting dimensions of watermark image
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
// creting jpg from original image
$image_path = '/path/to/image/folder/' . $image;
$image = imagecreatefromjpeg($image_path);
//something went wrong
if ($image === false) {
return false;
}
// getting the dimensions of original image
$size = getimagesize($image_path);
// placing the watermark 5px from bottom and right
$dest_x = $size[0] - $watermark_width - 5;
$dest_y = $size[1] - $watermark_height - 5;
// blending the images together
imagealphablending($image, true);
imagealphablending($watermark, true);
// creating the new image
imagecopy($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height);
imagejpeg($image);
// destroying and freeing memory
imagedestroy($image);
imagedestroy($watermark);
我想将这两个工作脚本合并为一个。我确信它的简单,所有代码都在这里,我只是不知道如何去关联一个进程到另一个进程。这是我能解释的最好的..谢谢!
有没有回答的问题,或者至少一个问题你可以描述你写的代码吗? – 2013-03-08 17:42:25
基本上,我想上传一个图像到S3(已经工作),但之前,我想为该图像添加水印(不工作)。 – Chrisl446 2013-03-08 17:50:22
您需要更具体地说明什么是不工作而不是“不工作”。 – 2013-03-08 17:53:28