PHP webmaster tools: Color tool or enter the color number/rgb to get a 1*1 repeat background image

PHP webmaster tools: Color tool or enter color number/rgb to get a 1*1 repeat background image; used for solid color backgrounds such as buttons

<?php
if($_GET["x"] == "cha"){
$color = isset($_POST['color']) ? $_POST['color'] : '#cccccc';
$width = 1; $height = 1;
$image = imagecreatetruecolor($width, $height);
if (strpos($color, '#') === 0) {
    sscanf($color, "#%2x%2x%2x", $red, $green, $blue);
} elseif (strpos($color, 'rgb(') === 0) { //只识别RGB,自己注意输入格式
    sscanf($color, "rgb(%d, %d, %d)", $red, $green, $blue);
} elseif (strpos($color, ',') > 0) {
    $color = "rgb($color)";
    sscanf($color, "rgb(%d, %d, %d)", $red, $green, $blue);
}else{
    exit("输入参考:#cccccc 或 rgb(100, 111, 222)");
}
$background_color = imagecolorallocate($image, $red, $green, $blue);
imagefill($image, 0, 0, $background_color);
//header('Content-Type: image/png');
ob_start();
imagepng($image);
$image_data = ob_get_clean();
$image_base64 = base64_encode($image_data);
//echo '<img src="data:image/png;base64,' . $image_base64 . '" alt="Image.Base64" />';
echo "\r\n\r\n<div class=\"back\" style=\"background:$color url(data:image/png;base64,",$image_base64,") repeat;\" >$color</div>";
imagedestroy($image);
exit();
}
?>
<!DOCTYPE html>
<html>
<head>
  <title>Generated Image</title>

<script type="text/javascript">
console.log("问题反馈电话:","15058593138");
console.log("问题反馈邮件:","[email protected]");
function $(objId){
return document.getElementById(objId);
}
function loadcha(xid) {
var xmlhttp;
var Stxt= "nums=aa";
$("tips").innerHTML = "正在加载...";
Stxt+="&color="+ encodeURIComponent($(xid).value);
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var btxt = xmlhttp.response;
if(btxt == "err01"){ $("tips").innerHTML = "!"; return false;}
$('tips').innerHTML = xmlhttp.response;
$('tipx').innerHTML = xmlhttp.response;
}
}
xmlhttp.open("POST", "?x=cha&tt="+Math.random(), true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send(Stxt);
}

</script>
<style>
#tips,.back{display:block;width:99.7%;height:88px;}
textarea{display:block;width:99.7%;height:200px;}
#xid{ height:28px;}
#tid{ height:34px;}
#submit{ height:36px;}
</style>
</head>
<body>

 <form class="form" id="form" method="POST" act="?act=cha" >
 <p>炫色器选择后点空白处 或 输入色号/rgb后点按钮,提交得到1*1的repeat背景</p>
 <input type="color" id="tid" name="tid" placeholder="请选择色号" value="#FF0000"  onchange="loadcha('tid')">
 <input type="text" id="xid" name="xid" placeholder="请输入色号" value="#FF0000">
 <input type="button" id="submit" value="提交查询" onclick="loadcha('xid')">
 <textarea id="tipx" style=""></textarea>
 <div id="tips"></div>
 </form>
</body>
</html>

Guess you like

Origin blog.csdn.net/YUJIANYUE/article/details/131607873