function genImage($width, $height, $fontsize, $font_path, $bg_color_str, $txt_color_str)
{
    header("Content-Type: image/png");
    // Create a new image resource
    $img = imagecreatetruecolor($width, $height);
    $bgColorArry = getRGB($bg_color_str);
    $txtColorArry = getRGB($txt_color_str);
    // Set default color values if the passed background- or textcolor is invalid.
    if (!$txtColorArry) {
        $txtColorArry = array("r" => 150, "g" => 150, "b" => 150);
    }
    if (!$bgColorArry) {
        $bgColorArry = array("r" => 204, "g" => 204, "b" => 204);
    }
    // define the color of the background and text color
    $bg_color = imagecolorallocate($img, $bgColorArry["r"], $bgColorArry["g"], $bgColorArry["b"]);
    $txt_color = imagecolorallocate($img, $txtColorArry["r"], $txtColorArry["g"], $txtColorArry["b"]);
    // fill the image with the background color
    imagefill($img, 0, 0, $bg_color);
    // The actual text to be written. E.g. "1280x720"
    $image_text = $width . "x" . $height;
    // calculate the x and y coordinate of the text so that it renders it at the center of the image.
    $bbox = imagettfbbox($fontsize, 0, $font_path, $image_text);
    $text_x = $bbox[0] + imagesx($img) / 2 - $bbox[4] / 2;
    $text_y = $bbox[1] + imagesy($img) / 2 - $bbox[5] / 2;
    // draw the text at the calculated x and y value with the desired color
    imagettftext($img, $fontsize, 0, $text_x, $text_y, $txt_color, $font_path, $image_text);
    // output the image to the browser.
    imagepng($img);
    // free the used resources
    imagedestroy($img);
}
        return $retval;
    }
}
$phpgw_info = array();
$phpgw_info["flags"]["currentapp"] = "admin";
$phpgw_info["flags"]["nonavbar"] = True;
$phpgw_info["flags"]["noheader"] = True;
include "../header.inc.php";
Header("Content-type: image/gif");
$border = 1;
//echo $filename;
$im = openGif($filename);
/* Open the provided file */
$bg = getRGB($phpgw_info["theme"]["navbar_bg"]);
/* get navbar theme */
$fg = getRGB($phpgw_info["theme"]["navbar_text"]);
$navbar_bg = ImageColorAllocate($im, $bg["r"], $bg["g"], $bg["b"]);
$navbar_fg = ImageColorAllocate($im, $fg["r"], $fg["g"], $fg["b"]);
$dk_gray = ImageColorAllocate($im, 128, 128, 128);
$lt_gray = ImageColorAllocate($im, 192, 192, 192);
$dx = ImageSX($im);
/* get image size */
$dy = ImageSY($im);
ImageFilledRectangle($im, 0, 0, $dx, $border, $dk_gray);
/* top */
ImageFilledRectangle($im, 0, 0, $border, $dy, $dk_gray);
/* left */
ImageFilledRectangle($im, $dx - $border - 1, 0, $dx, $dy, $lt_gray);
/* right */
ImageFilledRectangle($im, 0, $dy - $border - 1, $dx, $dy, $lt_gray);
/* bottom */
Example #3
0
function getWebColor($rgb)
{
    getRGB($rgb, $r, $g, $b);
    return "#" . sprintf("%02x%02x%02x", $r, $g, $b);
}
// ?
$images[61] = array("x" => 207, "y" => 10, "w" => 5);
// =
$letters = imagecreatefrompng($lettersPath);
$rgb = getRGB($leftTextColor);
$index = imagecolorexact($letters, 0, 0, 0);
imagecolorset($letters, $index, $rgb[0], $rgb[1], $rgb[2]);
$leftText = stripslashes(strtoupper($leftText));
$leftPos = $leftTextPosition;
for ($i = 0; $i < strlen($leftText); $i++) {
    $c = ord($leftText[$i]);
    imagecopy($im, $letters, $leftPos, 5, $images[$c]["x"], $images[$c]["y"], $images[$c]["w"], 6);
    $leftPos += $images[$c]["w"];
}
$letters = imagecreatefrompng($lettersPath);
$rgb = getRGB($rightTextColor);
$index = imagecolorexact($letters, 0, 0, 0);
imagecolorset($letters, $index, $rgb[0], $rgb[1], $rgb[2]);
$rightText = stripslashes(strtoupper($rightText));
$rightPos = $rightTextPosition;
for ($i = 0; $i < strlen($rightText); $i++) {
    $c = ord($rightText[$i]);
    imagecopy($im, $letters, $rightPos, 5, $images[$c]["x"], $images[$c]["y"], $images[$c]["w"], 6);
    $rightPos += $images[$c]["w"];
}
if ($save_file) {
    $save_path = JPATH_ROOT . DS . "components" . DS . "com_ninjarsssyndicator" . DS . "assets" . DS . "images" . DS . "buttons";
    if (!_isWritable($save_path . '/')) {
        exit("Cannot access {$save_path}\tdirectory!");
    }
    $img_name = $leftText . '-' . $rightText . '-' . time() . '.png';
Example #5
0
 function DrawPie()
 {
     $fsize = $this->Fsize;
     $image = imagecreate($this->a * 2 + 40, $this->b * 2 + 40);
     $PieCenterX = $this->a + 10;
     $PieCenterY = $this->b + 10;
     $DoubleA = $this->a * 2;
     $DoubleB = $this->b * 2;
     list($R, $G, $B) = getRGB(0);
     $colorBorder = imagecolorallocate($image, $R, $G, $B);
     $DataNumber = count($this->DataArray);
     //$DataTotal
     for ($i = 0; $i < $DataNumber; $i++) {
         $DataTotal += $this->DataArray[$i];
     }
     //算出数据和
     //填充背景
     imagefill($image, 0, 0, imagecolorallocate($image, 255, 255, 255));
     /* 
      ** 画每一个扇形 
      */
     $Degrees = 0;
     for ($i = 0; $i < $DataNumber; $i++) {
         $StartDegrees = round($Degrees);
         $Degrees += $this->DataArray[$i] / $DataTotal * 360;
         $EndDegrees = round($Degrees);
         $percent = number_format($this->DataArray[$i] / $DataTotal * 100, 1);
         if ($this->ColorArray[$i]) {
             $aColor = $this->ColorArray[$i];
         } else {
             $aColor = $this->getRanColor();
         }
         list($R, $G, $B) = getRGB(hexdec($aColor));
         $CurrentColor = imagecolorallocate($image, $R, $G, $B);
         if ($R > 60 and $R < 256) {
             $R = $R - 60;
         }
         if ($G > 60 and $G < 256) {
             $G = $G - 60;
         }
         if ($B > 60 and $B < 256) {
             $B = $B - 60;
         }
         $CurrentDarkColor = imagecolorallocate($image, $R, $G, $B);
         //画扇形弧
         imagearc($image, $PieCenterX, $PieCenterY, $DoubleA, $DoubleB, $StartDegrees, $EndDegrees, $CurrentColor);
         //画直线
         list($ArcX, $ArcY) = pie_point($StartDegrees, $this->a, $this->b);
         imageline($image, $PieCenterX, $PieCenterY, floor($PieCenterX + $ArcX), floor($PieCenterY + $ArcY), $CurrentColor);
         //画直线
         list($ArcX, $ArcY) = pie_point($EndDegrees, $this->a, $this->b);
         imageline($image, $PieCenterX, $PieCenterY, ceil($PieCenterX + $ArcX), ceil($PieCenterY + $ArcY), $CurrentColor);
         //填充扇形
         $MidPoint = round(($EndDegrees - $StartDegrees) / 2 + $StartDegrees);
         list($ArcX, $ArcY) = Pie_point($MidPoint, $this->a * 3 / 4, $this->b * 3 / 4);
         //simkai.ttf
         imagefilltoborder($image, floor($PieCenterX + $ArcX), floor($PieCenterY + $ArcY), $CurrentColor, $CurrentColor);
         //imagestring($image,$fsize,floor($PieCenterX + $ArcX-5),floor($PieCenterY + $ArcY-5),"中国".$percent."%",$colorBorder);
         //imagettftext ($image,12,0,floor($PieCenterX + $ArcX-5),floor($PieCenterY + $ArcY-5),$colorBorder,'simkai.ttf',$this->NameArray[$i]."(".$percent."%)");
         //画阴影
         if ($StartDegrees >= 0 and $StartDegrees <= 180) {
             if ($EndDegrees <= 180) {
                 for ($k = 1; $k < 15; $k++) {
                     imagearc($image, $PieCenterX, $PieCenterY + $k, $DoubleA, $DoubleB, $StartDegrees, $EndDegrees, $CurrentDarkColor);
                 }
             } else {
                 for ($k = 1; $k < 15; $k++) {
                     imagearc($image, $PieCenterX, $PieCenterY + $k, $DoubleA, $DoubleB, $StartDegrees, 180, $CurrentDarkColor);
                 }
             }
         }
         imagettftext($image, 12, 0, floor($PieCenterX + $ArcX - 5) - 66, floor($PieCenterY + $ArcY - 5), $colorBorder, 'simkai.ttf', $this->NameArray[$i] . "(" . $percent . "%)");
     }
     //输出生成的图片
     imagepng($image);
     imagedestroy($image);
 }
Example #6
0
 function findBorder($file)
 {
     global $config;
     $borderColor = '111';
     $width = exec($config->location . $file . ' -format "%[fx:w]" info:');
     $height = exec($config->location . $file . ' -format "%[fx:h]" info:');
     $dimensions = (object) array();
     // Find where the border starts on the left
     for ($i = 1; $i < $width; $i++) {
         $c = getRGB($file, $i, round($height / 2));
         if ($c == $borderColor) {
             $dimensions->x = $i + 1;
             break;
         }
     }
     // Find where the border starts on the top
     for ($i = 1; $i < $height; $i++) {
         $c = getRGB($file, round($width / 2), $i);
         if ($c == $borderColor) {
             $dimensions->y = $i + 1;
             break;
         }
     }
     // Find where the border stops on the right
     for ($i = $width; $i > 0; $i--) {
         $c = getRGB($file, $i, round($height / 2));
         if ($c == $borderColor) {
             $dimensions->width = $i - $dimensions->x;
             break;
         }
     }
     // Find where the border stops on the bottom
     for ($i = $height; $i > 0; $i--) {
         $c = getRGB($file, round($width / 2), $i);
         if ($c == $borderColor) {
             $dimensions->height = $i - $dimensions->y;
             break;
         }
     }
     return $dimensions;
 }
Example #7
0
<?php

header("Content-type: text/css");
/*
 * The dynamic css gives you the possibility to play with css
 * using some server-side calculated variables
 */
function getRGB($baseRGB)
{
    $baseRGB = round(216 * $baseRGB / 255) % 216;
    // only 216 web safe colors
    $RGB = array('00', '33', '66', '99', 'CC', 'FF');
    $R = $RGB[$baseRGB % 6];
    $G = $RGB[round($baseRGB / 36)];
    $B = $RGB[round($baseRGB / 6) % 6];
    return '#' . $R . $G . $B;
}
$ip = explode('.', $_SERVER['REMOTE_ADDR']);
$color = getRGB($ip[2]);
?>

a { color:<?php 
echo $color;
?>
; }
Example #8
0

$draw = [];
$handle = fopen($argv[1], "r");
if ($handle) {
    while (($line = fgets($handle)) !== false) {

	$line= trim($line);
	$opt = explode (":",$line);


	if ($opt[4] >= $thresh && $opt[4] <= 1000000) {
		# convert mu/km to colour
		$hue = $opt[5] * 0.1 ;
	
		$colour = getRGB($hue);
	
		array_push ($draw,getDraw($opt[0],$opt[1],$opt[2],$colour));
	}

    }

    fclose($handle);
} else {
    // error opening the file.
	print "cannot open file.\n";
} 

print json_encode($draw) . "\n";

Example #9
0
<?php

$safeColor = '#ffffff';
$safeColors = array('000000', '000033', '000066', '000099', '0000cc', '0000ff', '003300', '003333', '003366', '003399', '0033cc', '0033ff', '006600', '006633', '006666', '006699', '0066cc', '0066ff', '009900', '009933', '009966', '009999', '0099cc', '0099ff', '00cc00', '00cc33', '00cc66', '00cc99', '00cccc', '00ccff', '00ff00', '00ff33', '00ff66', '00ff99', '00ffcc', '00ffff', '330000', '330033', '330066', '330099', '3300cc', '3300ff', '333300', '333333', '333366', '333399', '3333cc', '3333ff', '336600', '336633', '336666', '336699', '3366cc', '3366ff', '339900', '339933', '339966', '339999', '3399cc', '3399ff', '33cc00', '33cc33', '33cc66', '33cc99', '33cccc', '33ccff', '33ff00', '33ff33', '33ff66', '33ff99', '33ffcc', '33ffff', '660000', '660033', '660066', '660099', '6600cc', '6600ff', '663300', '663333', '663366', '663399', '6633cc', '6633ff', '666600', '666633', '666666', '666699', '6666cc', '6666ff', '669900', '669933', '669966', '669999', '6699cc', '6699ff', '66cc00', '66cc33', '66cc66', '66cc99', '66cccc', '66ccff', '66ff00', '66ff33', '66ff66', '66ff99', '66ffcc', '66ffff', '990000', '990033', '990066', '990099', '9900cc', '9900ff', '993300', '993333', '993366', '993399', '9933cc', '9933ff', '996600', '996633', '996666', '996699', '9966cc', '9966ff', '999900', '999933', '999966', '999999', '9999cc', '9999ff', '99cc00', '99cc33', '99cc66', '99cc99', '99cccc', '99ccff', '99ff00', '99ff33', '99ff66', '99ff99', '99ffcc', '99ffff', 'cc0000', 'cc0033', 'cc0066', 'cc0099', 'cc00cc', 'cc00ff', 'cc3300', 'cc3333', 'cc3366', 'cc3399', 'cc33cc', 'cc33ff', 'cc6600', 'cc6633', 'cc6666', 'cc6699', 'cc66cc', 'cc66ff', 'cc9900', 'cc9933', 'cc9966', 'cc9999', 'cc99cc', 'cc99ff', 'cccc00', 'cccc33', 'cccc66', 'cccc99', 'cccccc', 'ccccff', 'ccff00', 'ccff33', 'ccff66', 'ccff99', 'ccffcc', 'ccffff', 'ff0000', 'ff0033', 'ff0066', 'ff0099', 'ff00cc', 'ff00ff', 'ff3300', 'ff3333', 'ff3366', 'ff3399', 'ff33cc', 'ff33ff', 'ff6600', 'ff6633', 'ff6666', 'ff6699', 'ff66cc', 'ff66ff', 'ff9900', 'ff9933', 'ff9966', 'ff9999', 'ff99cc', 'ff99ff', 'ffcc00', 'ffcc33', 'ffcc66', 'ffcc99', 'ffcccc', 'ffccff', 'ffff00', 'ffff33', 'ffff66', 'ffff99', 'ffffcc', 'ffffff');
if ($_POST['color']) {
    $aColor = getRGB($_POST['color']);
    $aDifference = array();
    foreach ($safeColors as $safeColor) {
        $aSafeColor = getRGB($safeColor);
        $rDifference = abs($aSafeColor['red'] - $aColor['red']);
        $gDifference = abs($aSafeColor['green'] - $aColor['green']);
        $bDifference = abs($aSafeColor['blue'] - $aColor['blue']);
        $totalDifference = $rDifference + $gDifference + $bDifference;
        $aDifference[$safeColor] = $totalDifference;
    }
    asort($aDifference);
    $keys = array_keys($aDifference);
    $values = array_values($aDifference);
    $closestColor = '#' . $keys[0];
}
function getRGB($color)
{
    $color = trim($color);
    $color = str_replace('#', '', $color);
    $type = 'hex';
    $comma = strpos($color, ',');
    if ($comma) {
        list($r, $g, $b) = explode(',', $color);
    } else {
        $r = hexdec(substr($color, 0, 2));
        $g = hexdec(substr($color, 2, 2));