/** * Image to Text * * Takes a given system image and recreates it with a given string * Function accepts arbitrary elements to use for markup * * @access public * @param string * @param string * @param string * @return string */ function image_to_text($data, $txt, $new_width = NULL, $new_height = NULL, $inline_element = 'span') { $img = imagecreatefromstring($data); $width = imagesx($img); $height = imagesy($img); // add abiilty to resize on the fly if ($new_width and $new_height) { $new = imagecreatetruecolor($new_width, $new_height); imagecopyresampled($new, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height); unset($img); $img = $new; $width = $new_width; $height = $new_height; unset($new); } $counter = 0; $output = ""; for ($i = 0; $i < $height; $i++) { for ($j = 0; $j < $width; $j++) { $counter = $counter % strlen($txt); $cindex = ImageColorAt($img, $j, $i); $rgb = ImageColorsForIndex($img, $cindex); $hex = rgb2hex(array($rgb['red'], $rgb['green'], $rgb['blue'])); $output .= '<' . $inline_element . ' style="color:#' . $hex . ';">' . substr($txt, $counter, 1) . '</' . $inline_element . '>'; $counter++; } $output .= "<br />"; } return $output; }
function avgimgcolorhook($file) { if (!$file->isImage()) { return; } try { if ($file->avgcolor() == "") { require_once kirby()->roots()->index() . '/vendor/autoload.php'; $color = \ColorThief\ColorThief::getColor($file->root(), 100); $file->update(['avgcolor' => rgb2hex($color)]); } } catch (Exception $e) { return response::error($e->getMessage()); } }
function colourBlend($col1, $col2, $factor) { $col1RGB = hex2rgb(prepareHex($col1)); $col2RGB = hex2rgb(prepareHex($col2)); $blend = array(); //echo ('/*'); for ($i = 0; $i < 3; $i++) { $min = min($col1RGB[$i], $col2RGB[$i]); $max = max($col1RGB[$i], $col2RGB[$i]); $blend[$i] = round($min + ($max - $min) * $factor); //echo ($i .': min '. $min . ', max '. $max .' = '. $blend[$i].'\n\r' ); } //echo ('*/'); return rgb2hex($blend); }
function dominant_color($path) { $i = imagecreatefromjpeg($path); $rTotal = 0; $gTotal = 0; $bTotal = 0; $total = 0; for ($x = 0; $x < imagesx($i); $x++) { for ($y = 0; $y < imagesy($i); $y++) { $rgb = imagecolorat($i, $x, $y); $r = $rgb >> 16 & 0xff; $g = $rgb >> 8 & 0xff; $b = $rgb & 0xff; $rTotal += $r; $gTotal += $g; $bTotal += $b; $total++; } } $rAverage = round($rTotal / $total); $gAverage = round($gTotal / $total); $bAverage = round($bTotal / $total); return rgb2hex(array($rAverage, $gAverage, $bAverage)); }
echo '</tr>' . chr(10); } } ?> </table> <h3>Table of "grey" web safe colors</h3> <table border="0" cellpadding="0" cellspacing="0" width="100%" class="websafetable"> <?php echo '<tr>' . chr(10); for ($i = 0; $i <= 255; $i += 51) { echo ' <td>'; //rgb_sample($i,$i,$i,''); $hsl = rgb2hsl($i, $i, $i); $hex = rgb2hex($i, $i, $i); $color = readable_color($i, $i, $i); echo chr(10) . '<div class="rgb-sample" style="background:' . $hex . '; color:' . $color . ';">' . chr(10); echo ' ' . $hex . '; rgb(' . $i . ',' . $i . ',' . $i . '); hsl(' . $hsl[0] . ',' . $hsl[1] . '%,' . $hsl[2] . '%); ' . chr(10); echo ' </td>' . chr(10); } echo '</tr>' . chr(10); ?> </table> <?php include '../inc/_wrap_after.php'; include '../inc/_sidebar.php'; include '../inc/_footer.php';
if ($_GET['mode'] == 'hex' || $_GET['mode'] == 'rgb' || $_GET['mode'] == 'hsl' || $_GET['color'] == 'Convert') { ?> <h3>Hue of new color (0-359)° [same saturation and lightness]</h3> <div class="color-hue"> <div class="label-radio"> <?php for ($i = 0; $i < 360; $i++) { if (fmod($i, 5) and abs($i - $h2) > 2) { continue; } $rgb = hsl2rgb($i, $s, $l); $del = $i - $h; if ($del > 0) { $del = '+' . $del; } echo ' <label style="background:' . rgb2hex($rgb[0], $rgb[1], $rgb[2]) . ';" title="' . $i . ' (' . $del . ')">'; echo '<input name="h2" type="radio" value="' . $i . '" title="' . $i . ' (' . $del . ')"'; if ($i == $h2) { echo ' checked="checked"'; } echo ' />'; echo '</label>' . chr(10); } ?> </div> </div> <?php } ?>
function compress_css() { // make these variables available locally global $file_selector; global $file_props; // first, get the css that was sent, referenced or uploaded $cssfile = get_sent_css(); // check if the user wants to see statistics if ($_REQUEST['opt_output_stats']) { // save the size of the code $start_size = strlen($cssfile); // save the current time $start = explode(' ', microtime()); } // check if no css was found if (!$cssfile) { // just die exit("/* You didn't upload anything or the stylesheet is empty - Ro" . "bson */"); } // temporarily change semicolons in web links $cssfile = str_replace('://', '[!semi-colon!]//', $cssfile); // remove html and css comments kill_comments($cssfile); // trim whitespace from the start and end $cssfile = trim($cssfile); // turn all rgb values into hex if ($_REQUEST['opt_rgb2hex']) { rgb2hex($cssfile); } // shorten colours if ($_REQUEST['opt_colours2hex']) { long_colours_to_short_hex($cssfile); } if ($_REQUEST['opt_hex2colours']) { long_hex_to_short_colours($cssfile); } // remove any extra measurements that aren't needed if ($_REQUEST['opt_remove_zeros']) { remove_zero_measurements($cssfile); } // seperate into selectors and properties sort_css($cssfile); // change font weight text into numbers if ($_REQUEST['opt_text_weights_to_numbers']) { font_weight_text_to_numbers($cssfile); } // check if any selectors are used twice and combine the properties if ($_REQUEST['opt_combine_identical_selectors']) { combine_identical_selectors(); } // remove any properties which are declared twice in one rule if ($_REQUEST['opt_remove_overwritten_properties']) { remove_overwritten_properties(); } // check if properties should be combined if ($_REQUEST['opt_combine_props_list']) { // for each rule in the file for ($n = 0; $n < count($file_props); $n++) { // attempt to combine the different parts combine_props_list($file_props[$n]); } } // for each rule in the file for ($n = 0; $n < count($file_props); $n++) { // run all the individual functions to reduce their size array_walk($file_props[$n], 'reduce_prop'); } // remove all the properties that were blanked out earlier remove_empty_rules(); // check if any rules are the same as other ones and remove the first ones if ($_REQUEST['opt_combine_identical_rules']) { combine_identical_rules(); } // one final run through to remove all unnecessary parts of the arrays remove_empty_rules(); $output = create_output(); // turn back colons $output = str_replace('[!semi-colon!]//', '://', $output); $output = stripslashes($output); // check if the user wants to view stats if ($_REQUEST['opt_output_stats']) { echo '<h1>Statistics</h1><ul>'; echo '<li>Original size: ' . round($start_size / 1024, 2) . ' kB (' . number_format($start_size) . ' B)</li>'; echo '<li>Final size: ' . round(strlen(strip_tags($output)) / 1024, 2) . ' kB (' . number_format(strlen(strip_tags($output))) . ' B)</li>'; echo '<li>Saved: ' . round(($start_size - strlen(strip_tags($output))) / 1024, 2) . ' kB (' . number_format($start_size - strlen(strip_tags($output))) . ' B)</li>'; echo '<li>Reduction: ' . round(100 - strlen(strip_tags($output)) / $start_size * 100, 2) . '%</li>'; echo '</ul>'; $finish = explode(' ', microtime()); // work out the differences between the times $seconds = $finish[1] - $start[1]; $miliseconds = $finish[0] - $start[0]; $duration = round($seconds + $miliseconds, 5); echo '<ul>'; echo '<li>Duration: ' . $duration . ' seconds</li>'; echo '</ul>'; echo '<ul>'; echo '<li>Rules: ' . count($file_selector) . '</li>'; for ($n = 0; $n < count($file_selector); $n++) { $selectors += count($file_selector[$n]); } for ($n = 0; $n < count($file_props); $n++) { $props += count($file_props[$n]); } echo '<li>Selectors: ' . $selectors . '</li>'; echo '<li>Properties: ' . $props . '</li>'; echo '</ul>'; echo '<h1>CSS</h1>'; } if ($_REQUEST['upload_link']) { $_REQUEST['upload_style'] = NULL; if (!$_POST['upload_link']) { $_POST = $_GET; } foreach ($_POST as $key => $value) { if ($value) { if (!$url) { $url .= '?' . $key . '=' . $value; } else { $url .= '&' . $key . '=' . $value; } } } echo '<ul><li><a href="http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . $url . '">Link to this output</a>.</ul>'; } echo $output; }
$etat = 'images/2off.png'; $couleur = '#FFFFFF'; $intensity = '0'; // Si la lampe a répondu (eRRRGGGBBBIII) if (strlen($output) == 13) { // On scan l'état de la lampe dans la réponse: "0" ou "1" if (substr($output, 0, 1) == '1') { $etat = 'images/2on.png'; } elseif (substr($output, 0, 1) != '0') { $erreur .= "La lampe n'a pas communiqué son état actuel. "; } // Couleur de la lampe dans la réponse: "RRGGGBBB" $r = substr($output, 1, 3); $g = substr($output, 4, 3); $b = substr($output, 7, 3); $couleur = rgb2hex(array($r, $g, $b)); // Intensité de l'éclairage $intensity = intval(substr($output, 10, 3)); } elseif ($output == '') { // timeout dans la plupart des cas $erreur .= 'La lampe semble être injoignale (timeout). '; } else { $erreur .= "La lampe n'a pas communiqué les bonnes informations. "; } ?> <!doctype html> <html> <head>
<td style="padding-left:4px; text-align:left; padding:0px;"><?php require_once "includes/rgb2hsv.php"; $online = true; if (!$online) { die("Das OCS wurde vorübergehend deaktiviert!"); } $json = file_get_contents("online.json"); $json = json_decode($json); $users = $json->users; function rgb2hex($str, $offset) { return hexdec(substr($str, $offset, 2)); } usort($users, function ($a, $b) { $hsv1 = RGB_TO_HSV(rgb2hex($a->namecolor, 0), rgb2hex($a->namecolor, 2), rgb2hex($a->namecolor, 4)); $hsv2 = RGB_TO_HSV(rgb2hex($b->namecolor, 0), rgb2hex($b->namecolor, 2), rgb2hex($b->namecolor, 4)); return 255 * ($hsv1["H"] - $hsv2["H"]); //hexdec(substr($a->namecolor, 0, 2)); }); $num = count($users); if ($num == 1) { ?> Im <a href="http://ocs.speedcube.de/" target="_blank">OCS</a> (online-cubing-system) ist <b>1</b> User online: <?php } elseif ($num == 0) { ?> Im <a href="http://ocs.speedcube.de/" target="_blank">OCS</a> (online-cubing-system) sind <b>keine</b> User online. <?php } else { ?> Im <a href="http://ocs.speedcube.de/" target="_blank">OCS</a> (online-cubing-system) sind <b><?php
$s2 = 0; } if ($s2 > 100) { $s2 = 100; } if ($l2 < 0) { $l2 = 0; } if ($l2 > 100) { $l2 = 100; } $rgb2 = hsl2rgb($h2, $s2, $l2); $r2 = $rgb2[0]; $g2 = $rgb2[1]; $b2 = $rgb2[2]; $hex2 = rgb2hex($r2, $g2, $b2); $hex2 = substr($hex2, 1); // remove '#' rgb_sample($r2, $g2, $b2, 'Second color'); } ?> <script type="text/javascript"> jQuery(function($){ $('.form-container').wrap('<fo'+'rm name="color" method="get" action="<?php echo basename(__FILE__); ?> "></fo'+'rm>'); }); </script>
echo '</label>' . chr(10); } ?> </div> </div> <div style="clear:both; float:none;"> <input type="submit" class="submit" name="color" value="Click" /> </div> </div><!-- .form-container --> <!-- Complementary colors --> <?php $rgb = hsl2rgb($h, $s, $l); $hex = rgb2hex($rgb[0], $rgb[1], $rgb[2]); $color = readable_color($rgb[0], $rgb[1], $rgb[2]); ?> <h3>Results</h3> <div class="color-results" style="<?php echo 'background-color:' . $hex . '; color:' . $color . ';'; ?> "> <?php hsl_sample($h, $s, $l, 'Basic color'); ?> <h3>Complementary colors:</h3> <?php
$graph = new CLineGraphDraw(getRequest('type')); $graph->setPeriod($timeline['period']); $graph->setSTime($timeline['stime']); // change how the graph will be displayed if more than one item is selected if (getRequest('batch')) { // set a default header if (count($hostNames) == 1) { $graph->setHeader($hostNames[0] . NAME_DELIMITER . _('Item values')); } else { $graph->setHeader(_('Item values')); } // hide triggers $graph->showTriggers(false); } if (isset($_REQUEST['from'])) { $graph->setFrom($_REQUEST['from']); } if (isset($_REQUEST['width'])) { $graph->setWidth($_REQUEST['width']); } if (isset($_REQUEST['height'])) { $graph->setHeight($_REQUEST['height']); } if (isset($_REQUEST['border'])) { $graph->setBorder(0); } foreach ($items as $item) { $graph->addItem($item['itemid'], GRAPH_YAXIS_SIDE_DEFAULT, getRequest('batch') ? CALC_FNC_AVG : CALC_FNC_ALL, rgb2hex(get_next_color(1))); } $graph->draw(); require_once dirname(__FILE__) . '/include/page_footer.php';
#!/usr/bin/env php <?php require_once __DIR__ . '/vendor/autoload.php'; function rgb2hex($r, $g = null, $b = null) { if (is_array($r) && count($r) == 3) { list($r, $g, $b) = $r; } $r = intval($r); $g = intval($g); $b = intval($b); $r = dechex($r < 0 ? 0 : ($r > 255 ? 255 : $r)); $g = dechex($g < 0 ? 0 : ($g > 255 ? 255 : $g)); $b = dechex($b < 0 ? 0 : ($b > 255 ? 255 : $b)); return '#' . (strlen($r) < 2 ? '0' : '') . $r . (strlen($g) < 2 ? '0' : '') . $g . (strlen($b) < 2 ? '0' : '') . $b; } foreach (glob(__DIR__ . '/content/posts/2*') as $postDir) { foreach (glob($postDir . '/*.jpg') as $img) { $metaFile = $img . '.txt'; $meta = file_exists($metaFile) ? file_get_contents($metaFile) : ''; if (strpos($meta, 'Avgcolor') !== false) { continue; } $avgColor = \ColorThief\ColorThief::getColor($img, 100); file_put_contents($metaFile, ($meta ? $meta . "\n\n----\n\n" : '') . "Avgcolor: " . rgb2hex($avgColor)); echo $img . ' => ' . rgb2hex($avgColor) . "\n"; } }
function getStylesForClasses($mapFile, $layerName) { $attr = "{'attributes':["; $map = new mapObj($mapFile); $layer = $map->getLayerByName($layerName); for ($i = 0; $i < $layer->numclasses; $i++) { $class = $layer->getClass($i); $className = $class->name; $index = 0; $patternString = ""; for ($j = 0; $j < $class->numstyles; $j++) { $style = $class->getStyle($j); error_log($style->color->red); error_log($style->color->green); error_log($style->color->blue); if ($style->color->red > -1 && $style->color->green > -1 && $style->color->blue > -1) { $color = rgb2hex([$style->color->red, $style->color->green, $style->color->blue]); } else { $color = ""; } if ($style->outlinecolor->red > -1 && $style->outlinecolor->green > -1 && $style->outlinecolor->blue > -1) { $outlineColor = rgb2hex([$style->outlinecolor->red, $style->outlinecolor->green, $style->outlinecolor->blue]); } else { $outlineColor = ""; } $width = $style->width; $size = $style->size; $symbol = $style->symbolname; $angle = $style->angle; $pattern = $style->getPatternArray(); foreach ($pattern as $value) { $patternString .= " " . $value; } $gap = $style->gap; $index++; $attr .= "{'color':'{$color}', 'outlinecolor':'{$outlineColor}', 'width':'{$width}', 'size':'{$size}', 'symbol':'{$symbol}', 'className':'{$className}', 'index':'{$index}', 'gap':'{$gap}', 'angle':'{$angle}', 'pattern':'{$patternString}'},"; } } $attr .= "]}"; return $attr; }
$color = explode(',', $_GET['color']); if (count($color) == 1) { // hex color $hex .= $_GET['color']; } if (count($color) == 3) { // must be 3 digits with comma // rgb, even if its a 0 // eg. 000,255,255 // first is reg, second is green, third is blue $rgb = explode(',', $_GET['color']); $r = $rgb[0]; $g = $rgb[1]; $b = $rgb[2]; // $_GET['hex'] = rgb2hex($r,$g,$b); $hex .= rgb2hex($r, $g, $b); // echo $_GET['color']; } if (count($color) > 3 || count($color) == 2) { if (isset($_GET['callback'])) { echo $_GET['callback'] . '(' . json_encode(array('err' => array('code' => 502, 'msg' => 'invalid search term'))) . ')'; } else { if (!isset($_GET['callback'])) { echo json_encode(array('err' => array('code' => 502, 'msg' => 'invalid search term'))); } } exit; } $_GET['hex'] = $hex; if ($service == "forrst") { $response = get_contents("https://forrst.com/api/v2/posts/list?post_type=snap");
<?php include '../include.php'; include '../inc/_header.php'; include '../inc/_wrap_before.php'; ?> <?php // randomize $rand_h = rand(0, 359); $rand_s = rand(0, 40) + 50; $rand_l = rand(0, 20) + 40; $rand_rgb = hsl2rgb($rand_h, $rand_s, $rand_l); $rand = rgb2hex($rand_rgb[0], $rand_rgb[1], $rand_rgb[2]); $bgrand = readable_color($rand_rgb[0], $rand_rgb[1], $rand_rgb[2]); ?> <h2>Convert HSL to RGB</h2> <p>You can convert color from HSL to RGB and from HSL to Hex or just click <?php echo random_link_hsl(); ?> .</p> <?php if (isset($_GET['h']) && isset($_GET['s']) && isset($_GET['l'])) { $h = $_GET['h']; $s = $_GET['s']; $l = $_GET['l']; hsl_sample($h, $s, $l, 'Basic color'); }
function hsl2hex($h, $s, $l) { return rgb2hex(hsl2rgb($h, $s, $l)); }
$result = DBselect($sql); while ($row = DBfetch($result)) { if ($row['i'] == $x) { continue; } if (!is_null($item_data)) { $item_data = ($item_data + $row['avg']) / 2; } else { $item_data = $row['avg']; } } } $db_values[$count][$itemid] = is_null($item_data) ? 0 : $item_data; $tmp_color = get_next_palette($palette, $palettetype); if (!isset($graph_data['colors'][$count])) { $graph_data['colors'][$count] = rgb2hex($tmp_color); } $date_caption = $scaletype == TIMEPERIOD_TYPE_HOURLY ? CHARTBAR_HOURLY_DATE_FORMAT : CHARTBAR_DAILY_DATE_FORMAT; $graph_data['legend'][$count] = zbx_date2str($date_caption, $start); $count++; } } foreach ($db_values as $item_data) { $graph->addSeries($item_data); } if (isset($itemid) && ($db_item = get_item_by_itemid($itemid))) { $graph->setUnits($db_item['units']); $graph->setSideValueType($db_item['value_type']); } } if (!isset($graph_data['captions'])) {
function hsl2hex($hsl) { $rgb = hsl2rgb($hsl); return rgb2hex($rgb); }
<td>Dark Accent Color</td> <td>Neutral Midtone Color</td> </tr> <tr> <?php ## Loop through 3 colors $completed = 1; for ($i = 1; $i <= 3; $i++) { print "<td>\n"; $rgbcolor = ""; $hexcolor = ""; $style = ""; if ($colors[$i]) { $colorarray = split(",", $colors[$i]); $rgbcolor = ${$colorvar}; $hexcolor = rgb2hex($colorarray); print "<div class=\"colorbox\" id=\"colorbox{$i}\" name=\"colorbox{$i}\" style=\"background-color:#{$hexcolor}\" OnClick=\"SelectColor({$i})\"></div>\n"; } else { print "<div class=\"colorbox\" id=\"colorbox{$i}\" name=\"colorbox{$i}\" OnClick=\"SelectColor({$i})\"></div>\n"; $completed = 0; } print "<input type=\"hidden\" name=\"color{$i}\" value=\"{$colors[$i]}\">\n"; print "</td>\n"; } ?> </tr> <tr> <td colspan="4" style="padding-top: 20px"> <input type="image" class="image" src="banners/<?php echo $banner->filename; ?>
} ?> </div> </div> <div style="clear:both; float:none;"> <input type="submit" class="submit" name="color" value="Click" /> </div> </div><!-- .form-container --> <!-- Complementary colors --> <h3>Results</h3> <?php $hex = rgb2hex($r, $g, $b); $hsl = rgb2hsl($r, $g, $b); $h = $hsl[0]; $s = $hsl[1]; $l = $hsl[2]; $color = readable_color($r, $g, $b); ?> <div class="color-results" style="<?php echo 'background-color:' . $hex . '; color:' . $color . ';'; ?> "> <?php rgb_sample($r, $g, $b, 'Basic color');
function color2hex($color) { $hsv[0] = ($color >> 16) / 360; $hsv[1] = ($color >> 8 & 255) / 255; $hsv[2] = ($color & 255) / 255; return rgb2hex(hsv2rgb($hsv)); }
<?php include '../lib/WideImage.php'; $hex = "#000000"; if (isset($_GET["color"])) { if ($_GET["color"] != "") { $color = $_GET["color"]; } } if (ctype_xdigit($color)) { //Is hex? $hex = $color; //echo "Hex color: " .$color.'<br />'; } else { $hex = rgb2hex($color); //echo "RGB color: " . $color .'<br />Hex conversion: ' . $hex . '<br />'; } //exit; $rgb = hex2rgb($hex); $im_handle = imagecreatefrompng('../img/icons/icon-arrow.png'); // 1. Load Image $original = WideImage::load($im_handle); // 2. Get Transparency Mask $mask = $original->getMask(); // 3. Dispose Original $original->destroy(); // 4. Create New Image $colorized = WideImage::createTrueColorImage($mask->getWidth(), $mask->getHeight()); // 5. Colorize Image $bg = $colorized->allocateColor($rgb[0], $rgb[1], $rgb[2]); $colorized->fill(0, 0, $bg);
function ct_hsvShade($color, $luminance, $saturation) { // Hex-Farbe in RGB und RGB in HSV umwandeln $hsvcolor = rgb2hls(hex2rgb($color)); // Saturation und Luminance der Farbe erhöhen $hsvcolor[1] = $hsvcolor[1] + $luminance; $hsvcolor[2] = $hsvcolor[2] + $saturation; return rgb2hex(hls2rgb($hsvcolor)); }
<?php $db = new SQLite3('../db/data.sqlite'); $result = $db->query('select * from data WHERE id=0;'); while ($row = $result->fetchArray()) { $mode = $row["mode"]; $brightness = $row["brightness"]; $r = $row["r"]; $g = $row["g"]; $b = $row["b"]; $parameter = $row["parameter"]; } $rgb = array($r, $g, $b); $hex = rgb2hex($rgb); $db->close();
function compress_css($cssfile) { // make these variables available locally global $file_selector; global $file_props; global $cssCompressor; // first, get the css that was sent, referenced or uploaded // save the size of the code $start_size = strlen($cssfile); // save the current time $start = explode(' ', microtime()); // temporarily change semicolons in web links $cssfile = str_replace('://', '[!semi-colon!]//', $cssfile); // remove html and css comments kill_comments($cssfile); // trim whitespace from the start and end $cssfile = trim($cssfile); // turn all rgb values into hex if ($cssCompressor['opt_rgb2hex']) { rgb2hex($cssfile); } // shorten colours if ($cssCompressor['opt_colours2hex']) { long_colours_to_short_hex($cssfile); } if ($cssCompressor['opt_hex2colours']) { long_hex_to_short_colours($cssfile); } // remove any extra measurements that aren't needed if ($cssCompressor['opt_remove_zeros']) { remove_zero_measurements($cssfile); } // seperate into selectors and properties sort_css($cssfile); // change font weight text into numbers if ($cssCompressor['opt_text_weights_to_numbers']) { font_weight_text_to_numbers($cssfile); } // check if any selectors are used twice and combine the properties if ($cssCompressor['opt_combine_identical_selectors']) { combine_identical_selectors(); } // remove any properties which are declared twice in one rule if ($cssCompressor['opt_remove_overwritten_properties']) { remove_overwritten_properties(); } // check if properties should be combined if ($cssCompressor['opt_combine_props_list']) { // for each rule in the file for ($n = 0; $n < count($file_props); $n++) { // attempt to combine the different parts combine_props_list($file_props[$n]); } } // for each rule in the file for ($n = 0; $n < count($file_props); $n++) { // run all the individual functions to reduce their size array_walk($file_props[$n], 'reduce_prop', $cssCompressor); } // remove all the properties that were blanked out earlier remove_empty_rules(); // check if any rules are the same as other ones and remove the first ones if ($cssCompressor['opt_combine_identical_rules']) { combine_identical_rules(); } // one final run through to remove all unnecessary parts of the arrays remove_empty_rules(); $output = create_output(); // turn back colons $output = str_replace('[!semi-colon!]//', '://', $output); $output = stripslashes($output); // gather statistics $stats['original_size'] = round($start_size / 1024, 2) . ' kB'; $stats['final_size'] = round(strlen(strip_tags($output)) / 1024, 2) . ' kB'; $stats['reduction'] = round(100 - strlen(strip_tags($output)) / $start_size * 100, 2) . '%'; $finish = explode(' ', microtime()); // work out the differences between the times $seconds = $finish[1] - $start[1]; $miliseconds = $finish[0] - $start[0]; $stats['duration'] = round($seconds + $miliseconds, 5); $stats['num_rules'] = count($file_selector); for ($n = 0; $n < count($file_selector); $n++) { $stats['num_selectors'] += count($file_selector[$n]); } for ($n = 0; $n < count($file_props); $n++) { $stats['num_props'] += count($file_props[$n]); } return array($output, $stats); }
function imgTableizr($imgSrc, $quality = 'medium', $width = 'no-resize') { global $colspan, $prevHex, $prevRGB, $currentHex, $currentRGB, $tdCount, $output; $output = array(); $explodedSrc = explode('.', $imgSrc); $ext = end($explodedSrc); switch ($ext) { case 'jpg' || 'jpeg': $img = imagecreatefromjpeg($imgSrc); break; case 'png': $img = imagecreatefrompng($imgSrc); break; case 'gif': $img = imagecreatefromgif($imgSrc); break; case 'bmp': $img = imagecreatefrombmp($imgSrc); break; default: return false; } if ($width != 'no-resize' && is_int($width) && $width > 0) { $img = imagescale($img, $width); } switch ($quality) { case 'medium': $threshold = 20; break; case 'low': $threshold = 30; break; case 'high': $threshold = 10; break; case 'maximum': $threshold = 0; break; case is_int($quality) && $quality >= 0: $threshold = $quality; break; case is_int($quality) && $quality < 0: $threshold = 0; break; default: return false; } $imgW = imagesx($img); $imgH = imagesy($img); array_push($output, '<table style="border-spacing:0;width:' . $imgW . 'px;height:' . $imgH . 'px;margin:0;padding:0;">'); for ($y = 0; $imgH > $y; $y++) { array_push($output, '<tr>'); for ($x = 0; $imgW > $x; $x++) { $rgb = imagecolorat($img, $x, $y); $currentRGB = array(0 => $rgb >> 16 & 0xff, 1 => $rgb >> 8 & 0xff, 2 => $rgb & 0xff); $currentHex = rgb2hex($currentRGB); if ($x != 0) { if (abs($currentRGB[0] - $prevRGB[0]) <= $threshold) { if (abs($currentRGB[1] - $prevRGB[1]) <= $threshold) { if (abs($currentRGB[2] - $prevRGB[2]) <= $threshold) { $colspan++; if ($x + 1 == $imgW) { generateCell(); } } else { generateCell(); } } else { generateCell(); } } else { generateCell(); } } else { $prevHex = $currentHex; $prevRGB = $currentRGB; } } array_push($output, '</tr>'); } array_push($output, '</table>'); imagedestroy($img); echo implode('', $output); }
function random_link_hsl() { $rand_h = rand(0, 359); $rand_s = rand(0, 100); $rand_l = rand(0, 100); $rand_rgb = hsl2rgb($rand_h, $rand_s, $rand_l); $rand = rgb2hex($rand_rgb[0], $rand_rgb[1], $rand_rgb[2]); $bgrand = readable_color($rand_rgb[0], $rand_rgb[1], $rand_rgb[2]); return '<!--googleoff: index--><a rel="nofollow" class="random" style="padding:0 2px; color:' . $rand . '; background:' . $bgrand . ';" href="' . basename($_SERVER['SCRIPT_FILENAME']) . '?mode=hsl&h=' . $rand_h . '&s=' . $rand_s . '&l=' . $rand_l . '" rel="nofollow">random color</a><!--googleon: index-->'; }