// Convert it to GD format $imageBits = ImageCreateFromString($image->body); // Copy it to proper spot in the destination print " Render image at {$nextX}, {$nextY}\n"; ImageCopy($imageOut, $imageBits, $nextX, $nextY, 0, 0, ImageSx($imageBits), ImageSy($imageBits)); // Draw a border around it ImageRectangle($imageOut, $nextX, $nextY, $nextX + ImageSx($imageBits), $nextY + ImageSy($imageBits), ImageColorAllocate($imageOut, 0, 0, 0)); // Update position for next image $nextX += THUMB_SIZE + GAP_SIZE; if ($nextX + THUMB_SIZE > $outX) { $nextX = BORDER_LEFT; $nextY += THUMB_SIZE + GAP_SIZE; } } // Get the bits of the destination image $imageFileOut = tempnam('/tmp', 'aws') . '.png'; ImagePNG($imageOut, $imageFileOut, 0); $imageBitsOut = file_get_contents($imageFileOut); unlink($imageFileOut); // Store the final image in S3 $key = 'page_image_' . md5($pageTitle) . '.png'; if (uploadObject($s3, BOOK_BUCKET, $key, $imageBitsOut, AmazonS3::ACL_PUBLIC)) { print " Stored final image in S3 using key '{$key}'\n"; print_r($messageDetail['History']); // Delete the message $sqs->delete_message($queueURL_Render, $receiptHandle); print " Deleted message from render queue\n"; } print "\n"; } }
function addCloudListItem($sdb, $s3, $city, $state, $date, $price, $category, $title, $description, $imagePath) { // Form key $key = md5($city . $state . $date . $price . $category . $title); // Fetch image, store original and thumbnail in S3 if ($imagePath !== null) { // Get original $imageIn = file_get_contents($imagePath); $imageMem = ImageCreateFromString($imageIn); // Render as-is to JPEG and read in $fileOut = tempnam("/tmp", "aws") . ".aws"; $ret = ImageJPEG($imageMem, $fileOut, 100); $imageOut = file_get_contents($fileOut); // Create thumbnail $thumbOut = thumbnailImage($imageOut, "image/jpg"); // Store original and thumbnail in S3 $imageKey = $key . '.jpg'; $thumbKey = $key . '_thumb.jpg'; if (!uploadObject($s3, CL_BUCKET, $imageKey, $imageOut, AmazonS3::ACL_PUBLIC, "image/jpeg") || !uploadObject($s3, CL_BUCKET, $thumbKey, $thumbOut, AmazonS3::ACL_PUBLIC, "image/jpeg")) { return false; } $imageURL = $s3->get_object_url(CL_BUCKET, $imageKey, "60 seconds"); $thumbURL = $s3->get_object_url(CL_BUCKET, $thumbKey, "60 seconds"); } else { $imageURL = null; $thumbURL = null; } // Store the description in S3 if (uploadObject($s3, CL_BUCKET, $key, $description, AmazonS3::ACL_PUBLIC)) { $descriptionURL = $s3->get_object_url(CL_BUCKET, $key, "60 seconds"); } else { return false; } // Form attributes $attrs = array('City' => $city, 'State' => $state, 'Date' => $date, 'Price' => $price, 'Category' => $category, 'Title' => $title, 'Description' => $descriptionURL); if ($imageURL !== null) { $attrs['Image'] = $imageURL; $attrs['Thumb'] = $thumbURL; } // Insert item $res = $sdb->put_attributes(CL_ITEM_DOMAIN, $key, $attrs, true); return $res->isOK(); }
print "Thumbnailing '{$bucketIn}' to '{$bucketOut}'\n"; // Create the S3 access object $s3 = new AmazonS3(); // Get object list from input bucket $objectsIn = getBucketObjects($s3, $bucketIn); // Process each object. Generate thumbnails only for images foreach ($objectsIn as $objectIn) { $key = $objectIn->Key; print "Processing item '{$key}':\n"; if (substr(guessType($key), 0, 6) == "image/") { $startTime = microtime(true); $dataIn = $s3->get_object($bucketIn, $key); $endTime = microtime(true); $contentType = guessType($key); printf("\tDownloaded from S3 in %.2f seconds.\n", $endTime - $startTime); $startTime = microtime(true); $dataOut = thumbnailImage($dataIn->body, $contentType); $endTime = microtime(true); printf("\tGenerated thumbnail in %.2f seconds.\n", $endTime - $startTime); $startTime = microtime(true); if (uploadObject($s3, $bucketOut, $key, $dataOut, AmazonS3::ACL_PUBLIC, $contentType)) { $endTime = microtime(true); printf("\tUploaded thumbnail to S3 in %.2f seconds.\n", $endTime - $startTime); } else { print "\tCould not upload thumbnail.\n"; } } else { print "\tSkipping - not an image\n"; } print "\n"; }
// Pull, process, post while (true) { // Pull the message from the queue $message = pullMessage($sqs, $queueURL_URL); if ($message != null) { // Extract message detail $messageDetail = $message['MessageDetail']; $receiptHandle = (string) $message['ReceiptHandle']; $pageURL = $messageDetail['Data']; // Fetch the page print "Processing URL '{$pageURL}':\n"; $html = file_get_contents($pageURL); print " Retrieved " . strlen($html) . " bytes of HTML\n"; // Store the page in S3 $key = 'page_' . md5($pageURL) . '.html'; if (uploadObject($s3, BOOK_BUCKET, $key, $html, AmazonS3::ACL_PUBLIC)) { // Get URL in S3 $s3URL = $s3->get_object_url(BOOK_BUCKET, $key); print " Uploaded page to S3 as '{$key}'\n"; // Form message to pass page along to parser $origin = $messageDetail['Origin']; $history = $messageDetail['History']; $history[] = 'Fetched by ' . $argv[0] . ' at ' . date('c'); $message = json_encode(array('Action' => 'ParsePage', 'Origin' => $origin, 'Data' => $s3URL, 'PageURL' => $pageURL, 'History' => $history)); // Pass the page along to the parser $res = $sqs->send_message($queueURL_Parse, $message); print " Sent page to parser\n"; if ($res->isOK()) { // Delete the message $sqs->delete_message($queueURL_URL, $receiptHandle); print " Deleted message from URL queue\n";
// Convert it to GD format $imageBits = ImageCreateFromString($image->body); // Copy it to proper spot in the destination print " Render image at {$nextX}, {$nextY}\n"; ImageCopy($imageOut, $imageBits, $nextX, $nextY, 0, 0, ImageSx($imageBits), ImageSy($imageBits)); // Draw a border around it ImageRectangle($imageOut, $nextX, $nextY, $nextX + ImageSx($imageBits), $nextY + ImageSy($imageBits), ImageColorAllocate($imageOut, 0, 0, 0)); // Update position for next image $nextX += THUMB_SIZE + GAP_SIZE; if ($nextX + THUMB_SIZE > $outX) { $nextX = BORDER_LEFT; $nextY += THUMB_SIZE + GAP_SIZE; } } // Get the bits of the destination image $imageFileOut = tempnam('/tmp', 'aws') . '.png'; ImagePNG($imageOut, $imageFileOut, 0); $imageBitsOut = file_get_contents($imageFileOut); unlink($imageFileOut); // Store the final image in S3 $key = 'page_image_' . md5($pageTitle) . '.png'; if (uploadObject($s3, $bucket, $key, $imageBitsOut, AmazonS3::ACL_PUBLIC)) { print " Stored final image in S3 using key '{$key}'\n"; print_r($messageDetail['History']); // Delete the message $sqs->delete_message($renderQueueURL, $receiptHandle); print " Deleted message from render queue\n"; } print "\n"; } }
$messageDetail = $message['MessageDetail']; $receiptHandle = (string) $message['ReceiptHandle']; $imageURLs = $messageDetail['Data']; print "Processing message with " . count($imageURLs) . " images:\n"; // Do the work $s3ImageKeys = array(); foreach ($imageURLs as $imageURL) { // Fetch the image print " Fetch image '{$imageURL}'\n"; $image = file_get_contents($imageURL); print " Retrieved " . strlen($image) . " byte image\n"; // Create a thumbnail $imageThumb = thumbnailImage($image, 'image/png'); // Store the image in S3 $key = 'image_' . md5($imageURL) . '.png'; if (uploadObject($s3, $bucket, $key, $imageThumb)) { print " Stored image in S3 using key '{$key}'\n"; $s3ImageKeys[] = $key; } } // If the images were processed, pass them to the image renderer if (count($imageURLs) == count($s3ImageKeys)) { // Form message to pass page along to image renderer $origin = $messageDetail['Origin']; $history = $messageDetail['History']; $pageTitle = $messageDetail['PageTitle']; $history[] = 'Processed by ' . $argv[0] . ' at ' . date('c'); $message = json_encode(array('Action' => 'RenderImages', 'Origin' => $origin, 'Data' => $s3ImageKeys, 'History' => $history, 'PageTitle' => $pageTitle)); // Pass the page along to the image renderer $res = $sqs->send_message($renderQueueURL, $message); print " Sent page to image renderer\n";
* http://aws.amazon.com/apache2.0/ * * or in the "license.txt" file accompanying this file. This file is * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS * OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the * License. */ error_reporting(E_ALL); require_once 'sdk.class.php'; require_once 'include/book.inc.php'; // Make sure that some arguments were supplied if ($argc < 3) { exit("Usage: " . $argv[0] . " bucket files...\n"); } // Get Bucket argument $bucket = $argv[1] == '-' ? BOOK_BUCKET : $argv[1]; // Create the S3 access object $s3 = new AmazonS3(); // Upload each file for ($i = 2; $i < $argc; $i++) { $file = $argv[$i]; $data = file_get_contents($file); $contentType = guessType($file); if (uploadObject($s3, $bucket, $file, $data, AmazonS3::ACL_PUBLIC, $contentType)) { print "Uploaded file '{$file}' " . "to bucket '{$bucket}'\n"; } else { exit("Could not " . "upload file '{$file}' " . "to bucket '{$bucket}'\n"); } } exit(0);
// Pull, process, post while (true) { // Pull the message from the queue $message = pullMessage($sqs, $urlQueueURL); if ($message != null) { // Extract message detail $messageDetail = $message['MessageDetail']; $receiptHandle = (string) $message['ReceiptHandle']; $pageURL = $messageDetail['Data']; // Fetch the page print "Processing URL '{$pageURL}':\n"; $html = file_get_contents($pageURL); print " Retrieved " . strlen($html) . " bytes of HTML\n"; // Store the page in S3 $key = 'page_' . md5($pageURL) . '.html'; if (uploadObject($s3, $bucket, $key, $html, AmazonS3::ACL_PUBLIC)) { // Get URL in S3 $s3URL = $s3->get_object_url($bucket, $key, "60 seconds"); print " Uploaded page to S3 as '{$key}'\n"; // Form message to pass page along to parser $origin = $messageDetail['Origin']; $history = $messageDetail['History']; $history[] = 'Fetched by ' . $argv[0] . ' at ' . date('c'); $message = json_encode(array('Action' => 'ParsePage', 'Origin' => $origin, 'Data' => $s3URL, 'PageURL' => $pageURL, 'History' => $history)); // Pass the page along to the parser $res = $sqs->send_message($parseQueueURL, $message); print " Sent page to parser\n"; if ($res->isOK()) { // Delete the message $sqs->delete_message($urlQueueURL, $receiptHandle); print " Deleted message from URL queue\n";
$snapshotId = (string) $item->snapshotId; $volumeId = (string) $item->volumeId; $startTime = (string) $item->startTime; $region->AddSnapshot(new Snapshot($snapshotId, $volumeId, $startTime)); } // Dump data structure for debugging //print_r($region); // Render the region into an image $image = $region->Draw(); // Store the image in a local file $imageOut = tempnam("/tmp", "aws") . ".gif"; ImageGIF($image, $imageOut); // Retrieve the image's bits $imageOutBits = file_get_contents($imageOut); $imageKey = 'ec2_diagram_' . date('Y_m_d_H_i_s') . '.gif'; if (uploadObject($s3, BOOK_BUCKET, $imageKey, $imageOutBits, AmazonS3::ACL_PUBLIC, "image/gif")) { $imageURL = $s3->get_object_url(BOOK_BUCKET, $imageKey); print "EC2 diagram is at {$imageURL}\n"; } // Region - Representation of an AWS region class Region { var $name; var $instances; public function __construct($name) { $this->Name = $name; $this->Instances = array(); } public function AddInstance($instance) {
$messageDetail = $message['MessageDetail']; $receiptHandle = (string) $message['ReceiptHandle']; $imageURLs = $messageDetail['Data']; print "Processing message with " . count($imageURLs) . " images:\n"; // Do the work $s3ImageKeys = array(); foreach ($imageURLs as $imageURL) { // Fetch the image print " Fetch image '{$imageURL}'\n"; $image = file_get_contents($imageURL); print " Retrieved " . strlen($image) . " byte image\n"; // Create a thumbnail $imageThumb = thumbnailImage($image, 'image/png'); // Store the image in S3 $key = 'image_' . md5($imageURL) . '.png'; if (uploadObject($s3, BOOK_BUCKET, $key, $imageThumb)) { print " Stored image in S3 using key '{$key}'\n"; $s3ImageKeys[] = $key; } } // If the images were processed, pass them to the image renderer if (count($imageURLs) == count($s3ImageKeys)) { // Form message to pass page along to image renderer $origin = $messageDetail['Origin']; $history = $messageDetail['History']; $pageTitle = $messageDetail['PageTitle']; $history[] = 'Processed by ' . $argv[0] . ' at ' . date('c'); $message = json_encode(array('Action' => 'RenderImages', 'Origin' => $origin, 'Data' => $s3ImageKeys, 'History' => $history, 'PageTitle' => $pageTitle)); // Pass the page along to the image renderer $res = $sqs->send_message($queueURL_Render, $message); print " Sent page to image renderer\n";
$snapshotId = (string) $item->snapshotId; $volumeId = (string) $item->volumeId; $startTime = (string) $item->startTime; $region->AddSnapshot(new Snapshot($snapshotId, $volumeId, $startTime)); } // Dump data structure for debugging //print_r($region); // Render the region into an image $image = $region->Draw(); // Store the image in a local file $imageOut = tempnam("/tmp", "aws") . ".gif"; ImageGIF($image, $imageOut); // Retrieve the image's bits $imageOutBits = file_get_contents($imageOut); $imageKey = 'ec2_diagram_' . date('Y_m_d_H_i_s') . '.gif'; if (uploadObject($s3, $bucket, $imageKey, $imageOutBits, AmazonS3::ACL_PUBLIC, "image/gif")) { $imageURL = $s3->get_object_url($bucket, $imageKey, "60 seconds"); print "EC2 diagram is at {$imageURL}\n"; } // Region - Representation of an AWS region class Region { var $name; var $instances; public function __construct($name) { $this->Name = $name; $this->Instances = array(); } public function AddInstance($instance) {
$username = ""; $region = ""; if (!empty($authToken) && !empty($deviceID) && !empty($fileName)) { $conn = mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD) or die("Error:Couldn't connect to server"); $db = mysql_select_db(DB_DBNAME, $conn) or die("Error:Couldn't select database"); $query = "SELECT * FROM users WHERE authToken = '{$authToken}'"; $result = mysql_query($query) or die("Error:Query Failed-1"); if (mysql_num_rows($result) == 1) { $row = mysql_fetch_array($result); $username = $row["email"]; $region = $row["region"]; } else { die("Error: Incorrect authToken"); } mysql_close($conn); $fileContents = file_get_contents($_FILES["uploadedFile"]["tmp_name"]); $newFileName = md5($username . $deviceID) . "_" . $fileName; $s3 = new AmazonS3(); //echo "s3 : " . $s3 . "<br>"; //echo "bucketname : " . S3_BUCKET_OR . "<br>"; //echo "newfilename : " . $newFileName . "<br>"; //echo "contents : " . $fileContents . "<br>"; //uploadObject($s3, $bucket, $key, $data, $acl = S3_ACL_PRIVATE, $contentType = "text/plain") if (uploadObject($s3, S3_BUCKET_OR, $newFileName, $fileContents, S3_ACL_PUBLIC, "binary/octet-stream")) { echo "Success"; } else { echo "Error: Upload failed"; } } else { echo "Error: Not all parameters set."; }