コード例 #1
0
ファイル: gd.php プロジェクト: franckysolo/php-color
<?php

// An example of Color using gd
require_once __DIR__ . '/../vendor/autoload.php';
use PhpColor\Color;
$colors = [new Color(222, 0, 0, 100), new Color(0, 222, 0, 100), new Color(0, 0, 222, 100), new Color(222, 222, 0, 100), new Color(0, 222, 222, 100), new Color(222, 0, 222, 100), new Color(222, 222, 222, 100), new Color(124, 222, 222, 100), new Color(222, 124, 222, 100), new Color(255, 0, 0, 0), new Color(255, 0, 0, 50), new Color(255, 0, 0, 75), new Color(255, 0, 0, 100)];
$bg = new Color(255, 255, 255, 0);
$image = imagecreatetruecolor(800, 100);
imagefill($image, 0, 0, $bg->toInt());
imagestring($image, 4, 10, 8, 'Color using gd php', Color::BLACK);
$x1 = 10;
$x2 = 60;
foreach ($colors as $k => $color) {
    imagefilledrectangle($image, $x1, 25, $x2, 75, $color->toInt());
    $x1 += 60;
    $x2 += 60;
}
imagepng($image);
imagedestroy($image);
header('Content-type: image/png');
コード例 #2
0
ファイル: svg.php プロジェクト: franckysolo/php-color
<?php

require_once __DIR__ . '/../vendor/autoload.php';
use PhpColor\Color;
$green = Color::fromInt(Color::GREEN);
$blue = Color::fromInt(Color::BLUE);
$red = Color::fromInt(Color::RED);
$orange = Color::fromInt(Color::ORANGE);
$yellow = Color::fromInt(Color::YELLOW);
$lightGreen = Color::fromArray([100, 0, 255, 0]);
?>
<svg width="1280">
<rect x="10" y="10" width="100" height="100" fill="<?php 
echo $red;
?>
" />
<rect x="120" y="10" width="100" height="100" fill="<?php 
echo $green;
?>
" />
<rect x="230" y="10" width="100" height="100" fill="<?php 
echo $blue;
?>
" />
<rect x="340" y="10" width="100" height="100" fill="<?php 
echo $orange;
?>
" />
<rect x="450" y="10" width="100" height="100" fill="<?php 
echo $yellow;
?>
コード例 #3
0
ファイル: css.php プロジェクト: franckysolo/php-color
<?php

require_once __DIR__ . '/../vendor/autoload.php';
use PhpColor\Color;
$green = Color::fromInt(Color::GREEN);
$blue = Color::fromInt(Color::BLUE);
$red = Color::fromInt(Color::RED);
$orange = Color::fromInt(Color::ORANGE);
$yellow = Color::fromInt(Color::YELLOW);
$alphaGreen = Color::fromArray([120, 0, 255, 0]);
$opaqueGreen = $alphaGreen->toHex(true);
?>
<!doctype html>
<html>
<head>
<style type="text/css">
div {
display: inline-block;
width: 100px;
height: 100px;
}
.blue {
background-color : <?php 
echo $blue;
?>
;
}
.green {
background-color : <?php 
echo $green;
?>
コード例 #4
0
ファイル: ColorTest.php プロジェクト: franckysolo/php-color
 public function testConstantsColors()
 {
     $color = Color::fromInt(Color::BLUE);
     $this->assertEquals(0, $color->getRed());
     $this->assertEquals(0, $color->getGreen());
     $this->assertEquals(255, $color->getBlue());
     $this->assertEquals(0, $color->getAlpha());
 }
コード例 #5
0
ファイル: web-colors.php プロジェクト: franckysolo/php-color
<?php

require_once __DIR__ . '/../vendor/autoload.php';
use PhpColor\Color;
// the web safe colors
$colors = [];
for ($r = 0; $r <= 17; $r += 3) {
    for ($g = 0; $g <= 17; $g += 3) {
        for ($b = 0; $b <= 17; $b += 3) {
            $array = [dechex($r), dechex($r), dechex($g), dechex($g), dechex($b), dechex($b)];
            $string = join('', $array);
            $color = Color::fromHex($string);
            if (!in_array($color, $colors)) {
                array_push($colors, $color);
            }
        }
    }
}
$count = count($colors);
?>
<!doctype html>
<html>
<head>
<style type="text/css">
.color {
	color:#fff;
	width:150px;
	height:150px;
	line-height: 150px;
	display: inline-block;
	text-align: center;