imagecolorstotal
Intervention/image
Supported Versions: PHP 4, PHP 5, PHP 7, PHP 8
Find out the number of colors in an image's palette
imagecolorstotal
(
GdImage $image
):
int
{
$img
=
$this
->
manager
()->
make
(
'tests/images/trim.png'
);
$img
->
limitColors
(
4
);
$this
->
assertLessThanOrEqual
(
5
,
imagecolorstotal
(
$img
->
getCore
()));
}
public function
testLimitColorsKeepTransparency
()
tests/GdSystemTest.php
{
$img
=
$this
->
manager
()->
make
(
'tests/images/star.png'
);
$img
->
limitColors
(
16
);
$this
->
assertLessThanOrEqual
(
17
,
imagecolorstotal
(
$img
->
getCore
()));
$this
->
assertTransparentPosition
(
$img
,
0
,
0
);
$this
->
assertColorAtPosition
(
'#0c02b4'
,
$img
,
6
,
12
);
$this
->
assertColorAtPosition
(
'#fcbe04'
,
$img
,
22
,
24
);
tests/GdSystemTest.php
{
$img
=
$this
->
manager
()->
make
(
'tests/images/star.png'
);
$img
->
limitColors
(
64
,
'#00ff00'
);
$this
->
assertLessThanOrEqual
(
65
,
imagecolorstotal
(
$img
->
getCore
()));
$this
->
assertTransparentPosition
(
$img
,
0
,
0
);
$this
->
assertColorAtPosition
(
'#04f204'
,
$img
,
12
,
10
);
$this
->
assertColorAtPosition
(
'#e40214'
,
$img
,
16
,
21
);
tests/GdSystemTest.php