Without seeing my image, I'm not sure there is an easy way to do this.
EDIT 2:
One thing that I noticed from my first edit is that it did not work for an image with transparency and did not have an opaque layer.
, . . .
<?php
$red = 28;
$green = 198;
$blue = 72;
$alpha = .48;
$img = imagecreatefrompng('test.png');
imagealphablending($img, false);
for ($y = 0; $y < imagesy($img); $y++) {
for ($x = 0; $x < imagesx($img); $x++) {
$rgb = imagecolorat($img, $x, $y);
$pixel_color = imagecolorsforindex($img, $rgb);
if($pixel_color['red'] == $red &&
$pixel_color['green'] == $green &&
$pixel_color['blue'] == $blue &&
$pixel_color['alpha'] == round(127 - ($alpha * 127))){
$color = imagecolorallocatealpha($img, 255, 255, 255, 127);
} else {
$oldR = ($pixel_color['red'] - $alpha * $red) / (1 - $alpha);
$oldG = ($pixel_color['green'] - $alpha * $green ) / (1 - $alpha);
$oldB = ($pixel_color['blue'] - $alpha * $blue) / (1 - $alpha);
$color = imagecolorallocatealpha($img, $oldR, $oldG, $oldB, $pixel_color['alpha']);
}
imagesetpixel($img, $x, $y, $color);
}
}
imagesavealpha($img, true);
imagepng($img, 'test_result.png');
→
→
→ . . , , .
EDIT:
, : RGB, -?
, . , , . , .
<?php
$red = 44;
$green = 215;
$blue = 56;
$alpha = .45;
$img = imagecreatefrompng('test2.png');
for ($y = 0; $y < imagesy($img); $y++) {
for ($x = 0; $x < imagesx($img); $x++) {
$rgb = imagecolorat($img, $x, $y);
$pixel_color = imagecolorsforindex($img, $rgb);
$oldR = ($pixel_color['red'] - $alpha * $red) / (1 - $alpha);
$oldG = ($pixel_color['green'] - $alpha * $green ) / (1 - $alpha);
$oldB = ($pixel_color['blue'] - $alpha * $blue) / (1 - $alpha);
$color = imagecolorallocate($img, $oldR, $oldG, $oldB);
imagesetpixel($img, $x, $y, $color);
}
}
imagesavealpha($img, true);
imagepng($img, 'test_result.png');
-
-
rgb, . :
out = alpha * new + (1 - alpha) * old
out - .
, , , :
old = (out - alpha * new) / (1 - alpha)
OLD ANSWER:
:
$white_color_transparent = imagecolorallocatealpha($img, 255, 255, 255, 127);
127 , , . .
:
$white_color = imagecolorallocatealpha($img, 255, 255, 255, 0);
$white_color = imagecolorallocate($img, 255, 255, 255);
(0 ), .
, :
$white_color_semi_transparent = imagecolorallocatealpha($img, 255, 255, 255, 40);
, , , .
. :
-
- 255,255,255,40
, :
- -, , , .
- -, , . . , , Photoshop, , . , PNG .
, . . , , , , , . , .