function main() { $is_error = false; //no errors yet . . . $continue = false; //continue on to next image in directory? if (isset($_GET['directory'])) { $directory = $_GET['directory']; if (substr($directory, -1) != '/') { $directory = $directory . '/'; } //add trailing slash show_directory($directory); } // set directory of images to work in if (isset($_GET['directory']) && isset($_GET['action'])) { $action = $_GET['action']; } else { // if no directory set, then display form to set the directory return; } echo "performing {$action} on directory {$directory}<br />"; $threshold = $_GET['threshold']; // set number of file in directory to start on if (isset($_GET['number'])) { $number = $_GET['number']; } else { $number = 0; } // start at the first file //compile list of files in directory $file_list = collect_files($directory); if (count($file_list) == 0) { return "Directory {$directory} is empty."; } //couldn't find anything $output_dir = 'images/output/'; $output = ''; $image_name = ''; switch ($action) { case 'to_data': if (!isset($file_list[$number])) { $output .= 'Finished!'; //all done! break; } //if $image = file_to_image($directory . $file_list[$number]); $data = image_to_data($image); break; case 'difference_series': if (!isset($file_list[$number]) || !isset($file_list[$number + 1])) { $output .= 'No more files to compare.'; //all done! break; } //if $a = file_to_image($directory . $file_list[$number]); $b = file_to_image($directory . $file_list[$number + 1]); if (!($image = image_combine($a, $b, 'difference'))) { $output .= 'ERROR trying to combine images ' . $file_list[$number] . ' and ' . $file_list[$number + 1]; $is_error = true; break; } //if $file_name = '(' . $file_list[$number] . ')-(' . $file_list[$number + 1] . ')'; $image_name = $file_name . '.png'; write_image($image, $output_dir, $file_name, 'png'); $continue = true; break; case 'image_to_hough': if (!isset($file_list[$number])) { $output .= 'No more files.'; //done! break; } //if if (!($image = file_to_image($directory . $file_list[$number]))) { return "could not create image from {$directory}{$file_list[$number]}"; } if (isset($_GET['threshold'])) { $threshold = $_GET['threshold']; } else { $threshold = 128; } echo '<img src="' . $directory . $file_list[$number] . '" />'; $image = image_to_hough($image, $threshold); $file_name = "hough({$file_list[$number]})"; $image_name = $file_name . '.png'; write_image($image, $output_dir, $file_name, 'png'); echo hough_to_image($output_dir . $file_name . '.png'); $continue = true; break; case 'average': if (!isset($file_list[$number])) { $output .= 'No more files to add.'; //all done! break; } //if $temp_path = 'images/temp/'; $temp_filename = 'temp'; //$image = imagecreatefromjpeg($directory . $file_list[$number]); if (!file_exists($directory . $file_list[$number])) { return "file {$directory}{$file_list[$number]} does not seem to exist.<br />"; } if (!($image = file_to_image($directory . $file_list[$number]))) { return "{$directory}{$file_list[$number]} is not an image file<br />"; } if (file_exists($temp_path . $temp_filename . '.png')) { echo "temp file found in {$temp_path}{$temp_filename}.png<br />"; if ($number == 0) { //there shouldn't be a temp file echo "temp file is from previous batch: deleting . . . <br />"; if (!unlink($temp_path . $temp_filename . '.png')) { echo "error: could not delete file {$temp_path}{$temp_filename}"; } } $temp = file_to_image($temp_path . $temp_filename . '.png'); } else { echo "{$temp_path}{$temp_filename}.png does not exist, creating . . . <br />"; if (!($temp = imagecreatetruecolor(imagesx($image), imagesy($image)))) { return 'could not create temporary image'; } } $num_in_series = count($file_list); $output .= "adding the {$number}th 1/{$num_in_series}th of image to temp.png"; $constant = 1.0 / $num_in_series; $image = image_apply_constant($image, $constant, 'multiply'); $image = image_combine($temp, $image, 'sum'); write_image($image, $temp_path, $temp_filename, 'png'); $continue = true; break; case 'sum_series': break; case 'threshold': if (!isset($file_list[$number])) { $output .= 'No more files.'; //all done! break; } //if if (isset($_GET['threshold'])) { $threshold = $_GET['threshold']; } else { $threshold = 34; } $image = file_to_image($directory . $file_list[$number]); $image = image_apply_constant($image, $threshold, 'threshold'); $image_name = 'thresh(' . $file_list[$number] . ').png'; write_image($image, $output_dir, "thresh({$file_list[$number]})", 'png'); $continue = true; break; } //switch $next = $number + 1; if ($is_error) { $output .= <<<OUTPUT <br>Ohhh crap, there was an error performing the action {$action} on directory {$directory}<br><br> Try next pair? <a href="?directory={$directory}&action={$action}&number={$next}">Sure.</a> OUTPUT; $continue = false; } else { $output .= <<<OUTPUT Success.<br> <img src="{$output_dir}{$image_name}" /> OUTPUT; } //if if ($continue) { $output .= <<<OUTPUT <a href="?number={$next}&action={$action}&directory={$directory}&threshold={$threshold}">continue</a><br />\t OUTPUT; } //if return $output; }
if (!$directory_traversal_error) { show_directory($directory); } else { echo $directory_traversal_error; } break; case "2": $directory_traversal_error = directory_traversal_check_3($directory, $base_path = "./documents"); if (!$directory_traversal_error) { show_directory($directory); } else { echo $directory_traversal_error; } break; default: show_directory($directory); break; } } ?> </div> <div id="side"> <a href="http://twitter.com/MME_IT" target="blank_" class="button"><img src="./images/twitter.png"></a> <a href="http://be.linkedin.com/in/malikmesellem" target="blank_" class="button"><img src="./images/linkedin.png"></a> <a href="http://www.facebook.com/pages/MME-IT-Audits-Security/104153019664877" target="blank_" class="button"><img src="./images/facebook.png"></a> <a href="http://itsecgames.blogspot.com" target="blank_" class="button"><img src="./images/blogger.png"></a>
?> </p> </div> <?php } // show directory level $url = $this->url_alphacontent; switch (@$this->currentdirectorylevel) { case 'directory': if ($this->params->get('showdirectory')) { $n = $this->numsections; $p = $this->percent; $directory = $this->directory; $c = $this->numcols; $cs = $this->colspan; show_directory($n, $p, $c, $cs, $url, $directory, $this->params, $this->menuid); } break; case 'section': show_section($url, $this->directory, $this->params, $this->menuid); break; case 'category': show_category($url, $this->directory, $this->params, $this->menuid, $this->pagination); break; } if ($this->contentdescriptiondirectory && $this->params->get('positiondescription') == '1' && @$this->currentdirectorylevel == 'directory') { ?> <div id="descriptiondirectory"> <p> <?php echo JHTML::_('content.prepare', $this->contentdescriptiondirectory);