public function executeGenerate(sfWebRequest $request) { //data passes from index -> generate -> view. generate uses redirect at end. //hidden input field $this->generate_mosaic = $request->getPostParameter("generate"); if ($this->generate_mosaic == "1") { $base_path = "/var/www/symfony/web/uploads/"; //this is where the images go. $all_files = $request->getFiles(); $file = $all_files["image"]; $fname = $file["name"]; $fmime = $file["type"]; $ftmp = $file["tmp_name"]; //temp path $fsize = $file["size"]; $new_fname = uniqid(); //random name while (file_exists($base_path . $new_fname)) { $new_fname = uniqid(); } $img_path = $base_path . $new_fname; move_uploaded_file($ftmp, $img_path); //move image from temp path to uploads path. $img = ImageManipulation::imagecreatefrom($img_path); //see lib/image_lib.php. returns Image object. $img_width = imagesx($img); $img_height = imagesy($img); $img_ratio = $img_height / $img_width; $user_width = $request->getPostParameter("size"); //specified by user. $cell_sizes = array("small" => 5, "medium" => 15, "large" => 30); //user uses semantic descriptions (eg. "small"). if (array_key_exists($user_width, $cell_sizes)) { $cell_size = $cell_sizes[$user_width]; //match semantic user size with pixel value from $cell_sizes } else { $cell_size = $cell_sizes["medium"]; //default } $user_large_mosaic = $request->getPostParameter("large_mosaic"); //Checkbox for large mosaic $mosaic_width = 600; $mosaic_height = ceil($mosaic_width * $img_ratio); //Height adjusts to ratio. $new_img_width = $mosaic_width / $cell_size; //Image shrunk down so that later, $new_img_width * $cell_size = $mosaic_w $new_img_height = ceil($new_img_width * $img_ratio); $size_arr = getimagesize($img_path); //getimagesize() gets size from path; imagesx() gets size from Image object. ImageManipulation::resize_image($img_path, $img, $size_arr, $new_img_width, $new_img_height); //See lib/image_lib.php. No returns, resizes image. $keywords = $request->getPostParameter("keywords"); if (empty($keywords)) { $keywords = "cars"; //Default } $this->getUser()->setAttribute("img_path", $img_path); //Set Session variable. That way, if user refreshes, mosaic is still there. $this->getUser()->setAttribute("cell_size", $cell_size); //Same for cell sizes. $this->getUser()->setAttribute("keywords", $keywords); //Same for key } $this->redirect("/browse"); //on to view! }
//mega: AIzaSyALc9l8tOL3WZiGQ1Av3CsLsJdZyt477KA //noname: AIzaSyC9VwjNP3Yrk0pdsQeidKMuVJhnj70OfA0 use_javascript("https://www.google.com/jsapi?key=AIzaSyC9VwjNP3Yrk0pdsQeidKMuVJhnj70OfA0"); //See https://code.google.com/apis/console/#project:326513611386:overview use_javascript("formatted_colors.js"); use_javascript("google_images.js"); //use_javascript("jquery-ui.js"); //use_stylesheet("jquery-ui.css"); use_javascript("base64.js"); use_javascript("canvas2image.js"); if (isset($img_path)) { ?> <div class="mosaic-wrapper"> <?php $img = ImageManipulation::imagecreatefrom($img_path); //Returns Image object. MosaicGenerator::printCanvasMosaic($img, $cell_size, $keywords); //Defines three Javascript variables: The color matrix, the size of each image, and the keywords. ?> <script src="/js/generate_mosaic.js"> </script> <!-- Picks up three variables from printCanvasMosaic(), creates canvas mosaic !--> <div class="mosaic-actions"> <div class="tweak-size"> <p>Mosaic Size: </p> <select> <option value="300">Small </option> <option value="600" selected>Medium </option> <option value="900">Large </option> <option value="1600">Huge </option> </select>