当前位置: 首页>>代码示例>>PHP>>正文


PHP rgb2hex函数代码示例

本文整理汇总了PHP中rgb2hex函数的典型用法代码示例。如果您正苦于以下问题:PHP rgb2hex函数的具体用法?PHP rgb2hex怎么用?PHP rgb2hex使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了rgb2hex函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: image_to_text

/**
 * 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;
}
开发者ID:justinhernandez,项目名称:convert,代码行数:42,代码来源:useless_fun.php

示例2: avgimgcolorhook

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());
    }
}
开发者ID:lyoshenka,项目名称:travelblog,代码行数:15,代码来源:avg_img_color.php

示例3: colourBlend

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);
}
开发者ID:mbudm,项目名称:artpro,代码行数:15,代码来源:functions.color.php

示例4: dominant_color

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));
}
开发者ID:eberhardtsmith,项目名称:dinerporn,代码行数:24,代码来源:dominant-color.php

示例5: chr

        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';
开发者ID:webvitalii,项目名称:web-services,代码行数:31,代码来源:websafe.php

示例6: color

if ($_GET['mode'] == 'hex' || $_GET['mode'] == 'rgb' || $_GET['mode'] == 'hsl' || $_GET['color'] == 'Convert') {
    ?>
		<h3>Hue of new color (0-359)&deg; [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 
}
?>
开发者ID:webvitalii,项目名称:web-services,代码行数:30,代码来源:new_color_hue.php

示例7: compress_css

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]);
        }
//.........这里部分代码省略.........
开发者ID:GerHobbelt,项目名称:CompactCMS,代码行数:101,代码来源:css_compressor.php

示例8: elseif

$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>
开发者ID:benja135,项目名称:light-controller,代码行数:31,代码来源:index.php

示例9: die

<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 
开发者ID:Nerogar,项目名称:ocs5,代码行数:31,代码来源:ocs_online.php

示例10: hsl2rgb

        $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>
		
开发者ID:webvitalii,项目名称:web-services,代码行数:30,代码来源:color_gradient.php

示例11: chr

    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 
开发者ID:webvitalii,项目名称:web-services,代码行数:31,代码来源:hsl_clicker.php

示例12: CLineGraphDraw

$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';
开发者ID:omidmt,项目名称:zabbix-greenplum,代码行数:31,代码来源:chart.php

示例13: rgb2hex

#!/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";
    }
}
开发者ID:lyoshenka,项目名称:travelblog,代码行数:28,代码来源:avgcolor.php

示例14: getStylesForClasses

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;
}
开发者ID:smagic39,项目名称:mapfilestyler,代码行数:41,代码来源:MapScriptHelper.php

示例15: explode

 $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");
开发者ID:ekdevdes,项目名称:colorrs-api,代码行数:31,代码来源:index.php


注:本文中的rgb2hex函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。