PHP | imagecolorexact()函数

这个 imagecolorexact() 函数是PHP中的一个内置函数,用于获取图像调色板中指定颜色的索引。在创建的图像文件中,仅解析图像中使用的颜色。仅在调色板中出现的颜色不会被解析。

null

语法:

int imagecolorexact ( $image, $red, $green, $blue )

参数: 该函数接受上述四个参数,如下所述:

  • $image: 它由一个图像创建函数返回,例如imagecreatetruecolor()。它用于创建图像的大小。
  • $red: 此参数用于设置红色分量的值。
  • $green: 此参数用于设置绿色分量的值。
  • $blue: 此参数用于设置蓝色组件的值。

返回值: 成功时,此函数返回调色板中指定颜色的索引,如果颜色不存在,则返回-1。

下面的程序说明了 imagecolorexact() 函数。

项目1:

<?php
// Set the image into variable
$image = imagecreatefrompng(
// Create an array containing colors and image
$colors = Array();
$colors [] = imagecolorexact( $image , 10, 15, 20);
$colors [] = imagecolorexact( $image , 30, 180, 70);
$colors [] = imagecolorexact( $image , 12, 55, 25);
$colors [] = imagecolorexact( $image , 154, 25, 52);
print_r( $colors );
// Free from memory
imagedestroy( $image );
?>


输出:

Array ( 
    [0] => 659220 
    [1] => 2012230 
    [2] => 800537 
    [3] => 10098996 
)

项目2:

<?php
// Set the image into variable
$image = imagecreatefrompng(
// Create an array containing colors and image
$colors = Array(
$colors [] = imagecolorexact( $image , 0, 153, 0),
$colors [] = imagecolorexact( $image , 0, 0, 0),
$colors [] = imagecolorexact( $image , 255, 255, 255),
$colors [] = imagecolorexact( $image , 100, 100, 52)
);
print_r( $colors );
// Free from memory
imagedestroy( $image );
?>


输出:

Array ( 
    [0] => 39168 
    [1] => 0 
    [2] => 16777215 
    [3] => 6579252 
)

相关文章:

参考: http://php.net/manual/en/function.imagecolorexact.php

© 版权声明
THE END
喜欢就支持一下吧
点赞10 分享