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]); } }
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]); } }
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; }
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]); } }
public static function colorize(&$i, $color, $light = 0) { imagetruecolortopalette($i, true, 256); $r = hexdec(substr($color, 0, 2)); $g = hexdec(substr($color, 2, 2)); $b = hexdec(substr($color, 4, 2)); $colors = imageColorsTotal($i); if ($r < -255 || $r > 255 || ($g < -255 || $g > 255) || ($b < -255 || $b > 255)) { return; } $rR = $rG = $rB = 1 / 3; for ($line = 0; $line < $colors; $line++) { $indexColor = imagecolorsforindex($i, $line); $color = min(255, abs($indexColor['red'] * $rR + $indexColor['green'] * $rG + $indexColor['blue'] * $rB) + $light); $_r = min(255, $color + $r); $_g = min(255, $color + $g); $_b = min(255, $color + $b); imagecolorset($i, $line, $_r, $_g, $_b); } }
case 'GIF': $im = imageCreateFromGIF($image_path); $image_create_fun = 'imageGIF'; 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']);