3 <script src
="https://code.jquery.com/jquery-2.1.4.min.js"></script
>
7 background
-color
: blue
;
23 // Check if image file is a actual image or fake image
24 if(isset($_POST["submit"])) {
25 $ironlak_colours = array(
37 "ffe04e" => "Pineapple Park",
40 "de791b" => "Dieci Poes",
41 "f47d31" => "Halloween",
42 "f58427" => "Tues Afterburn",
44 "fdd29d" => "Smoothie",
49 "571b1e" => "Sirum Black-Red",
50 "8b0a02" => "Matador",
53 "cd4552" => "Isla Rose",
56 "9c0159" => "Moberry",
59 "f6aec4" => "Delicious",
62 "dd9ba5" => "Fantasia",
63 "fde6e0" => "Teegs Love",
65 "7e3e98" => "Pose Sushi",
68 "c2739d" => "Furious",
71 "0a024e" => "Panther",
72 "62609a" => "Eggplant",
73 "7f76b7" => "Phantom",
74 "7d81be" => "Sofles Violence",
77 "231f20" => "Augor's Blackout",
78 "00447b" => "Midnight",
79 "0068a9" => "Phat1's True Royal",
81 "00aeef" => "Enue's Bonggg!",
82 "78bde8" => "Torquay",
83 "89d3f4" => "Atmosphere",
86 "006b6e" => "Neverland",
89 "2abdb1" => "Frazetta",
90 "8fd1c5" => "Linz Iceberg",
96 "6cb43f" => "Cameleon",
97 "b3d78b" => "Reals Sublime",
98 "e6eebc" => "Whizbang",
100 "514e25" => "Askew's Olivia",
101 "677717" => "Guacamole",
102 "9ea615" => "Gangrene",
103 "ac9601" => "Banos Asbestos",
104 "d4d110" => "Kryptonite",
108 "434c3d" => "Lazy Grey",
109 "a0a1a5" => "Battleship",
110 "c5c6c8" => "Washington",
111 "f0f1f2" => "Smoulder",
114 "a8a9ad" => "Bright Chrome",
116 "ffffff" => "Whitest Possible",
117 "000000" => "Blackest Possible"
120 function colourDiff($rgb1, $rgb2) {
121 $red1 = hexdec(substr($rgb1,0,2));
122 $green1 = hexdec(substr($rgb1,2,2));
123 $blue1 = hexdec(substr($rgb1,4,2));
125 $red2 = hexdec(substr($rgb2,0,2));
126 $green2 = hexdec(substr($rgb2,2,2));
127 $blue2 = hexdec(substr($rgb2,4,2));
129 return abs($red1 - $red2) +
abs($green1 - $green2) +
abs($blue1 - $blue2) ;
132 function closest_colour($rgb, array $colours) {
133 $smallest_diff = 766;
136 foreach($colours as $hex => $name)
138 if(colourDiff($rgb, $hex) < $smallest_diff) {
139 $smallest_diff = colourDiff($rgb, $hex);
147 $cost_per_length = $_POST['wood_cost'];
148 $wood_length = $_POST['wood_length'];
149 $wood_size = $_POST['wood_size'];
151 $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
152 if($check !== false
) {
153 $colour_count = array();
154 $icolour_count = array();
155 $image = imagecreatefrompng($_FILES["fileToUpload"]["tmp_name"]);
156 $ironlak_sprite = array();
158 echo "<div class='sprite'>Original sprite:<br />";
160 echo "<table border='0' cellpadding='0' cellspacing='0'>";
161 for($i=0; $i<$check[1]; $i++
) {
163 for($j=0; $j<$check[0]; $j++
) {
164 $rgb = imagecolorsforindex($image, imagecolorat($image, $j, $i));
170 str_pad(dechex($rgb['red']), 2, '0', STR_PAD_LEFT
) .
171 str_pad(dechex($rgb['green']), 2, '0', STR_PAD_LEFT
) .
172 str_pad(dechex($rgb['blue']), 2, '0', STR_PAD_LEFT
);
173 if($a == 127) $hex = "ffffff";
176 echo "<td width='4' height='4' class='$hex' bgcolor='#$hex' r='$r' g='$g' b='$b' a='$a'></td>";
177 $colour_count[$hex] = isset($colour_count[$hex]) ?
$colour_count[$hex]+
1 : 1;
179 echo "<td width='4' height='4' bgcolor='#$hex' r='$r' g='$g' b='$b' a='$a'></td>";
182 $ironlak_sprite[$i][$j] = closest_colour($hex, $ironlak_colours);
186 echo '</table></div>';
188 echo "<div class='sprite'>Ironlak sprite:<br />";
190 echo "<table border='0' cellpadding='0' cellspacing='0'>";
191 for($i=0; $i<$check[1]; $i++
) {
193 for($j=0; $j<$check[0]; $j++
) {
194 $rgb = imagecolorsforindex($image, imagecolorat($image, $j, $i));
199 $ihex = $ironlak_sprite[$i][$j];
200 if($a == 127) $ihex = "ffffff";
203 echo "<td width='4' height='4' class='$ihex' bgcolor='#$ihex' r='$r' g='$g' b='$b' a='$a'></td>";
204 $icolour_count[$ihex] = isset($icolour_count[$ihex]) ?
$icolour_count[$ihex]+
1 : 1;
206 echo "<td width='4' height='4' bgcolor='#$ihex' r='$r' g='$g' b='$b' a='$a'></td>";
211 echo '</table></div>';
212 echo '<div style="clear: both;"></div>';
213 $total_blocks = array_sum($colour_count);
214 $lengths_required = ceil($total_blocks*$wood_size/$wood_length);
218 echo 'Physical dimensions (metres)<br />';
219 echo 'Width: ' . $check[0] * $wood_size . '<br />';;
220 echo 'Height: ' . $check[1] * $wood_size;
224 echo 'Wood cost breakdown<br />';
225 echo '<table border=1>
227 <td>Total blocks</td>
228 <td>No of ' . $wood_length . 'm lengths required</td>
229 <td>Cost @ ' . $cost_per_length . ' per length</td>
232 <td>' . $total_blocks . '</td>
233 <td>' . $lengths_required . '</td>
234 <td>' . $lengths_required * $cost_per_length . '</td>
238 $wood_cost = $lengths_required * $cost_per_length;
242 echo 'Colour cost breakdown<br /><br >';
243 echo '<div class="sprite">Original colour table:<br />';
245 echo '<table border=1>
251 foreach($colour_count as $colour => $qty) {
252 echo "<tr class='colour-row' id='$colour'><td bgcolor='$colour'></td><td>$colour</td><td>$qty</td></tr>";
255 echo '</table></div>';
257 echo '<div class="sprite">Ironlak colour table:<br />';
259 echo '<table border=1>
263 <td>Coverage (m^2)</td>
266 foreach($icolour_count as $colour => $qty) {
267 echo "<tr class='colour-row' id='$colour'><td bgcolor='$colour'></td><td>" . $ironlak_colours[$colour] . "</td><td>" . $qty * ($wood_size * $wood_size) . "</td><td>" . ceil(($qty * ($wood_size * $wood_size))/2.2) . "</td></tr>";
268 $num_cans+
=+
ceil(($qty * ($wood_size * $wood_size))/2.2);
271 echo '</table></div>';
273 echo '<div style="clear: both;"></div>';
276 echo 'Paint cost:<br />';
278 $cost_per_can = 6.36;
279 if($num_cans <= 199 ) {
280 $cost_per_can = 6.60;
283 if($num_cans <= 59 ) {
284 $cost_per_can = 6.76;
287 if($num_cans <= 35 ) {
291 if($num_cans <= 11 ) {
292 $cost_per_can = 7.16;
295 if($num_cans <= 5 ) {
296 $cost_per_can = 7.65;
298 $paint_cost = $num_cans * $cost_per_can;
299 echo "$num_cans cans @ $cost_per_can each: $paint_cost";
302 $total_cost = $wood_cost +
$paint_cost;
303 echo '<div style="font-size: 40px">Total cost (wood+paint): ' . $total_cost . '</div>';
310 $
( ".colour-row" ).hover(function() {
311 var colour
= $
(this
).attr('id');
313 $
("." + colour
).toggleClass("highlighted");