itsureboy Posted March 8, 2013 Share Posted March 8, 2013 I have a script that uploads files uploaded through my website directly to my Amazon s3 bucket.This never saves the file permanetly to my server, just as a temp_file_locationThis works perfect alone.However,I am trying to now add a watermark to the image before passing the temp_file_location to the s3 function to upload.My question is, how can I use the code below, with the temp_file and then return a new temp_file (which is the watermarked version)Here is just the code for the watermarker, I need this to start with the temp_file and leave me with a new temp_file_location: $temp_file_name = $_FILES['theFile']['tmp_name']; $image = $temp_file_name; // 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 = imagecreatefromjpeg($temp_file_name); //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 - 10; $dest_y = $size[1] - $watermark_height - 10; // 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); //HERE I NEED A $temp_file_name TO BE THE UPDATED FILE WITH THE WATERMARK TO PASS TO THE S3 FUNCTION. // destroying and freeing memory imagedestroy($image); imagedestroy($watermark); Any ideas??Thanks ahead!! Quote Link to comment https://forums.phpfreaks.com/topic/275416-return-updated-temp-file-back-after-watermark-added/ Share on other sites More sharing options...
requinix Posted March 8, 2013 Share Posted March 8, 2013 imagepng can write the image back out to a file... Quote Link to comment https://forums.phpfreaks.com/topic/275416-return-updated-temp-file-back-after-watermark-added/#findComment-1417573 Share on other sites More sharing options...
itsureboy Posted March 8, 2013 Author Share Posted March 8, 2013 (edited) I know I was trying to use imagejpg(); but couldn't get it to work.Heres the amazon s3 code thats works alone: 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']; $temp_file_name = $_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($temp_file_name, "BUCKETNAME", $image, S3::ACL_PUBLIC_READ, array(), $imageType)) { //success } else{ //error } But before the putObjectFile above , is where I want to implement this: $temp_file_name = $_FILES['theFile']['tmp_name']; $image = $temp_file_name; // 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 = imagecreatefromjpeg($temp_file_name); //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 - 10; $dest_y = $size[1] - $watermark_height - 10; // 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); //HERE I NEED A $temp_file_name TO BE THE UPDATED FILE WITH THE WATERMARK TO PASS TO THE S3 FUNCTION. // destroying and freeing memory imagedestroy($image); imagedestroy($watermark); I just need to link the variable to the function above and then output that variable again updated to pass it to S3 putObjectFile. Hope I didn't confuse you too much. Edited March 8, 2013 by itsureboy Quote Link to comment https://forums.phpfreaks.com/topic/275416-return-updated-temp-file-back-after-watermark-added/#findComment-1417575 Share on other sites More sharing options...
Solution requinix Posted March 8, 2013 Solution Share Posted March 8, 2013 Right, and I'm saying to use imagepng() to write the new image back out on top of the old image. You say you tried that? What was your code and what was the problem? Quote Link to comment https://forums.phpfreaks.com/topic/275416-return-updated-temp-file-back-after-watermark-added/#findComment-1417599 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.