45b39ad6cc1be4c603a9fadb6a4fc45d04c72fb6
3 // Check if image file is a actual image or fake image
4 if(isset($_POST["submit"])) {
5 $cost_per_length = $_POST['wood_cost'];
6 $wood_length = $_POST['wood_length'];
7 $wood_size = $_POST['wood_size'];
8 $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
10 $colour_count = array();
11 $image = imagecreatefrompng($_FILES["fileToUpload"]["tmp_name"]);
12 echo "<table border='0' cellpadding='0' cellspacing='0'>";
13 for($i=0; $i<$check[1]; $i++
) {
15 for($j=0; $j<$check[0]; $j++
) {
16 $rgb = imagecolorsforindex($image, imagecolorat($image, $j, $i));
22 str_pad(dechex($rgb['red']), 2, '0', STR_PAD_LEFT
) .
23 str_pad(dechex($rgb['green']), 2, '0', STR_PAD_LEFT
) .
24 str_pad(dechex($rgb['blue']), 2, '0', STR_PAD_LEFT
);
25 if($a == 127) $hex = "#ffffff";
26 echo "<td width='4' height='4' bgcolor='$hex' r='$r' g='$g' b='$b' a='$a'></td>";
29 $colour_count[$hex] = isset($colour_count[$hex]) ?
$colour_count[$hex]+
1 : 1;
35 $total_blocks = array_sum($colour_count);
36 $lengths_required = ceil($total_blocks*$wood_size/$wood_length);
40 echo 'Physical dimensions (metres)<br />';
41 echo 'Width: ' . $check[0] * $wood_size . '<br />';;
42 echo 'Height: ' . $check[1] * $wood_size;
46 echo 'Cost breakdown<br />';
47 echo '<table border=1>
50 <td>No of ' . $wood_length . 'm lengths required</td>
51 <td>Cost @ ' . $cost_per_length . ' per length</td>
54 <td>' . $total_blocks . '</td>
55 <td>' . $lengths_required . '</td>
56 <td>' . $lengths_required * $cost_per_length . '</td>
61 echo 'Colour breakdown<br />';
63 echo '<table border=1>
69 foreach($colour_count as $colour => $qty) {
70 echo "<tr><td bgcolor='$colour'></td><td>$colour</td><td>$qty</td></tr>";