<?php
|
/*---------------------------------------------------------------*/
|
/*
|
Titre : Extrait un canal de couleur d'une image
|
|
URL : https://phpsources.net/code_s.php?id=956
|
Date édition : 15 Fév 2019
|
*/
|
/*---------------------------------------------------------------*/
|
|
function imagechannel($img , $red=255 , $green=0 , $blue=0){
|
//$img = imagechannel($img, 0, 255, 0); // canal vert
|
//$img = imagechannel($img, 0, 0, 255); // canal bleu
|
//$img = imagechannel($img, 255, 255, 0); // canal jaune
|
|
|
$red = intval($red);
|
if ($red > 255 || $red < 0){
|
$red = 255;
|
}
|
$green = intval($green);
|
if ($green > 255 || $green < 0){
|
$green = 0;
|
}
|
$blue = intval($blue);
|
if ($blue > 255 || $blue < 0){
|
$blue = 0;
|
}
|
|
if ($red == 255 && $green == 255 && $blue == 255){
|
return $img;
|
}
|
|
$colors_num = imagecolorstotal($img);
|
|
for($i=0;$i<$colors_num;$i++) {
|
$color = imagecolorsforindex($img, $i);
|
$r = $red / 255 * $color["red"];
|
$g = $green / 255 * $color["green"];
|
$b = $blue / 255 * $color["blue"];
|
imagecolorset($img, $i, $r, $g, $b);
|
}
|
return $img;
|
}
|
|
?>
|
|
|