示例#1
0
 static function colorize($image, $rgb_code)
 {
     imageTrueColorToPalette($image, true, 256);
     $num_colors = imageColorsTotal($image);
     for ($x = 0; $x < $num_colors; $x++) {
         list($r, $g, $b) = array_values(imageColorsForIndex($image, $x));
         $gray_scale = ($r + $g + $b) / 3 / 0xff;
         imageColorSet($image, $x, $gray_scale * $rgb_code[0], $gray_scale * $rgb_code[1], $gray_scale * $rgb_code[2]);
     }
 }
示例#2
0
文件: badge.php 项目: habb0/mobbo
function Colorize($IMG, $RGB)
{
    imageTrueColorToPalette($IMG, true, 256);
    $numColors = imageColorsTotal($IMG);
    for ($x = 0; $x < $numColors; $x++) {
        list($r, $g, $b) = array_values(imageColorsForIndex($IMG, $x));
        $grayscale = ($r + $g + $b) / 3 / 0xff;
        imageColorSet($IMG, $x, $grayscale * $RGB[0], $grayscale * $RGB[1], $grayscale * $RGB[2]);
    }
}
     //for solid images
     if (imagecolorstotal(${$image}) == 1) {
         $index = 0;
     } else {
         $index = 1;
     }
     imageColorSet(${$image}, $index, $rl, $gl, $bl);
 }
 if ($fill) {
     //2 for fill, 1 for line
     if (imagecolorstotal(${$image}) == 2) {
         $index = 0;
     } else {
         $index = 2;
     }
     imageColorSet(${$image}, $index, $rf, $gf, $bf);
 }
 $W = ImageSX(${$image});
 $H = ImageSY(${$image});
 $X = $xs[$num];
 $Y = $ys[$num];
 if ($xMin > $X) {
     $xMin = $X;
 }
 if ($yMin > $Y) {
     $yMin = $Y;
 }
 if ($xMax < $X + $W) {
     $xMax = $X + $W;
 }
 if ($yMax < $Y + $H) {
示例#4
0
if($lightBorder['b'] > 255){
	$lightBorder['b'] = 255;
}

// For now, all borders are dark
//$lightBorder = "000000";
$darkBorder = "000000";


$image = imageCreateFromPNG($iconDirectoryPath . $iconName);
$phpFillIndex = imageColorClosest($image,$existingFill['r'],$existingFill['g'],$existingFill['b']);
imageColorSet($image,$phpFillIndex,$fill['r'],$fill['g'],$fill['b']);
$phpDarkBorderIndex = imageColorClosest($image,$existingDarkBorder['r'],$existingDarkBorder['g'],$existingDarkBorder['b']);
imageColorSet($image,$phpDarkBorderIndex,$darkBorder['r'],$darkBorder['g'],$darkBorder['b']);
$phpLightBorderIndex = imageColorClosest($image,$existingLightBorder['r'],$existingLightBorder['g'],$existingLightBorder['b']);
imageColorSet($image,$phpLightBorderIndex,$lightBorder['r'],$lightBorder['g'],$lightBorder['b']);

header('Content-type: image/png');
imagePNG($image);
imageDestroy($image);


/**
 * @param    $hex string        6-digit hexadecimal color
 * @return    array            3 elements 'r', 'g', & 'b' = int color values
 * @desc Converts a 6 digit hexadecimal number into an array of
 *       3 integer values ('r'  => red value, 'g'  => green, 'b'  => blue)
 */
function hex2int($hex) {
        return array( 'r' => hexdec(substr($hex, 0, 2)), // 1st pair of digits
                      'g' => hexdec(substr($hex, 2, 2)), // 2nd pair
示例#5
0
 public function image_colorize($rgb)
 {
     imageTrueColorToPalette($this->imageResized, true, 256);
     $numColors = imageColorsTotal($this->imageResized);
     for ($x = 0; $x < $numColors; $x++) {
         list($r, $g, $b) = array_values(imageColorsForIndex($this->imageResized, $x));
         // calculate grayscale in percent
         $grayscale = ($r + $g + $b) / 3 / 0xff;
         imageColorSet($this->imageResized, $x, $grayscale * $rgb[0], $grayscale * $rgb[1], $grayscale * $rgb[2]);
     }
     return true;
 }
示例#6
0
文件: badge.php 项目: habb0/HabboPHP
 function image_colorize4(&$img, $rgb)
 {
     imageTrueColorToPalette($img, true, 256);
     $numColors = imageColorsTotal($img);
     for ($x = 0; $x < $numColors; $x++) {
         list($r, $g, $b) = array_values(imageColorsForIndex($img, $x));
         $grayscale = ($r + $g + $b) / 3 / 0xff;
         imageColorSet($img, $x, $grayscale * $rgb[0], $grayscale * $rgb[1], $grayscale * $rgb[2]);
     }
 }
示例#7
0
function grayscale(&$im)
{
    $total = imagecolorstotal($im);
    for ($i = 0; $i < $total; $i++) {
        $arr = imageColorsForIndex($im, $i);
        $r = colorgray($arr);
        imageColorSet($im, $i, $r["red"], $r["green"], $r["blue"]);
    }
    return $im;
}
        $index = 1;
    }
    imageColorSet($im_src, $index, $r, $g, $b);
}
if ($fill) {
    list($r, $g, $b) = array_values(str_split($fill, 2));
    $r = hexdec($r);
    $g = hexdec($g);
    $b = hexdec($b);
    //2 for fill, 1 for line
    if (imagecolorstotal($im_src) == 2) {
        $index = 0;
    } else {
        $index = 2;
    }
    imageColorSet($im_src, $index, $r, $g, $b);
}
if ($size) {
    $width = imagesx($im_src);
    $height = imagesy($im_src);
    $w = $width * $size;
    $h = $height * $size;
    $im = imagecreatetruecolor($w, $h);
    /* making the new image transparent */
    $background = imagecolorallocate($im, 254, 0, 0);
    ImageColorTransparent($im, $background);
    // make the new temp image all transparent
    imagealphablending($im, false);
    // turn off the alpha blending to keep the alpha channel
    imagesavealpha($im, true);
    imagecopyresampled($im, $im_src, 0, 0, 0, 0, $w, $h, $width, $height);
示例#9
0
         break;
     case 'PNG':
         $im = imageCreateFromPNG($image_path);
         $image_create_fun = 'imagePNG';
 }
 if ($_POST['image_type'] !== 'original') {
     $image_create_fun = 'image' . $_POST['image_type'];
 }
 if ($_POST['black_white'] == 'yes') {
     if (imageIsTrueColor($im)) {
         imagetruecolortopalette($im, false, 256);
     }
     for ($i = 0, $colors = imageColorsTotal($im); $i < $colors; $i++) {
         $color = imageColorsForIndex($im, $i);
         $gray = round($color['red'] * 0.229 + $color['green'] * 0.587 + $color['red'] * 0.114);
         imageColorSet($im, $i, $gray, $gray, $gray);
     }
 }
 $file_name = '';
 $extention = $_POST['image_type'];
 if ($_POST['image_type'] == 'jpeg') {
     $extention = 'jpg';
 }
 if ($_POST['image_type'] == 'original') {
     $file_name = $_FILES['image']['name'];
 } else {
     if (count(explode('.', $_FILES['image']['name'])) > 1) {
         $file_name = explode('.', $_FILES['image']['name']);
         array_pop($file_name);
         $file_name = implode('.', $file_name);
     }