3 <script src
="https://code.jquery.com/jquery-2.1.4.min.js"></script
>
7 background
-color
: blue
;
17 // Check if image file is a actual image or fake image
18 if(isset($_POST["submit"])) {
19 $cost_per_length = $_POST['wood_cost'];
20 $wood_length = $_POST['wood_length'];
21 $wood_size = $_POST['wood_size'];
22 $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
23 if($check !== false
) {
24 $colour_count = array();
25 $image = imagecreatefrompng($_FILES["fileToUpload"]["tmp_name"]);
26 echo "<table border='0' cellpadding='0' cellspacing='0'>";
27 for($i=0; $i<$check[1]; $i++
) {
29 for($j=0; $j<$check[0]; $j++
) {
30 $rgb = imagecolorsforindex($image, imagecolorat($image, $j, $i));
36 str_pad(dechex($rgb['red']), 2, '0', STR_PAD_LEFT
) .
37 str_pad(dechex($rgb['green']), 2, '0', STR_PAD_LEFT
) .
38 str_pad(dechex($rgb['blue']), 2, '0', STR_PAD_LEFT
);
39 if($a == 127) $hex = "ffffff";
42 echo "<td width='4' height='4' class='$hex' bgcolor='#$hex' r='$r' g='$g' b='$b' a='$a'></td>";
43 $colour_count[$hex] = isset($colour_count[$hex]) ?
$colour_count[$hex]+
1 : 1;
45 echo "<td width='4' height='4' bgcolor='#$hex' r='$r' g='$g' b='$b' a='$a'></td>";
52 $total_blocks = array_sum($colour_count);
53 $lengths_required = ceil($total_blocks*$wood_size/$wood_length);
57 echo 'Physical dimensions (metres)<br />';
58 echo 'Width: ' . $check[0] * $wood_size . '<br />';;
59 echo 'Height: ' . $check[1] * $wood_size;
63 echo 'Cost breakdown<br />';
64 echo '<table border=1>
67 <td>No of ' . $wood_length . 'm lengths required</td>
68 <td>Cost @ ' . $cost_per_length . ' per length</td>
71 <td>' . $total_blocks . '</td>
72 <td>' . $lengths_required . '</td>
73 <td>' . $lengths_required * $cost_per_length . '</td>
78 echo 'Colour breakdown<br />';
80 echo '<table border=1>
86 foreach($colour_count as $colour => $qty) {
87 echo "<tr class='colour-row' id='$colour'><td bgcolor='$colour'></td><td>$colour</td><td>$qty</td></tr>";
96 $
( ".colour-row" ).hover(function() {
97 var colour
= $
(this
).attr('id');
99 $
("." + colour
).toggleClass("highlighted");