Inspect color transparency
Separate the two exact endpoints from every partially transparent value between them.
#7c3aed00 - alpha 0
transparent
#7c3aed73 - alpha 0.45
partial
#7c3aedff - alpha 1
opaque
Do not collapse partial alpha into a boolean
isTransparent() is true only at alpha 0. isOpaque() is true only at alpha 1. A partially transparent color satisfies neither.
Test both endpoints explicitly
Read getAlpha() when your application needs the continuous value rather than an endpoint classification.
<?php
use PhpColor\Color\Color;
$source = Color::parse('#7c3aed');
foreach ([0.0, 0.45, 1.0] as $alpha) {
$color = $source->withAlpha($alpha);
printf("%.2f transparent=%d opaque=%d\n",
$alpha,
$color->isTransparent(),
$color->isOpaque(),
);
}
// 0.00 transparent=1 opaque=0
// 0.45 transparent=0 opaque=0
// 1.00 transparent=0 opaque=1
use PhpColor\Color\Color;
$source = Color::parse('#7c3aed');
foreach ([0.0, 0.45, 1.0] as $alpha) {
$color = $source->withAlpha($alpha);
printf("%.2f transparent=%d opaque=%d\n",
$alpha,
$color->isTransparent(),
$color->isOpaque(),
);
}
// 0.00 transparent=1 opaque=0
// 0.45 transparent=0 opaque=0
// 1.00 transparent=0 opaque=1
Transparency does not reveal the visible color
Alpha describes coverage. The visible RGB result still depends on the backdrop and compositing order.
TransparentAlpha equals exactly 0.
PartialAlpha is greater than 0 and less than 1.
OpaqueAlpha equals exactly 1.
Visible resultComposite against a known backdrop before evaluating appearance.