It is necessary to read the image into an array of pixel color values ​​or into an array of bytes so that you can manually change the color values ​​of the pixels, and then convert this array back into an image. In C #, I did this, but in PHP I can't find it ((

  • one
  • Yes, it helped, thanks. Just what is the color scheme - "10779184, 9403447, 10518581, 10388300, 9601838, 11045174, 10585394, ..." ?? How to divide the color into RGB or how to work with this scheme ?? - GHosT
  • one
    Well, an example of the translation in rgb, you can look in the documentation - php.net/manual/en/function.imagecolorat.php - Bookin
  • one
    Also in the description, “If PHP is compiled with GD 2.0 or higher and a truecolor image is transmitted, the function returns an integer RGB value for a pixel. To select individual components of the red, green, or blue channels, use bit shift and masking:" - Bookin

1 answer 1

I will make a comment as an answer: To get the color index, use the imagecolorat function

To get the values ​​for all pixels of the image, you need to bypass them all, getting the width and height of the image:

$width = imagesx($resource); $height = imagesy($resource); for($x = 0; $x < $width; $x++) { for($y = 0; $y < $height; $y++) { // pixel color at (x, y) $color = imagecolorat($resource, $x, $y); } } 

To get individual rgba values ​​from the index, use the bitwise offset:

 $im = imagecreatefrompng("php.png"); $rgb = imagecolorat($im, 10, 15); $r = ($rgb >> 16) & 0xFF; $g = ($rgb >> 8) & 0xFF; $b = $rgb & 0xFF; var_dump($r, $g, $b); 

To get these values ​​in the array, you can use the imagecolorsforindex function

 $im = imagecreatefrompng("php.png"); $rgb = imagecolorat($im, 10, 15); $colors = imagecolorsforindex($im, $rgb); var_dump($colors); 

Sources:

stackoverflow response

documentation