S
S
savage_me2020-02-28 13:59:22
PHP
savage_me, 2020-02-28 13:59:22

How to get the color of all the pixels in an image without iterating through the pixels in two loops?

It is possible to get the color of the pixels by their coordinates by looping through everything horizontally and vertically, using
imagecolorat($thumb, $x, $y)

Is it possible to get the colors of all pixels without iterating in two loops?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Sokolov, 2020-02-28
@savage_me

If the picture is in an uncompressed format, for example, BMP, you can probably read an array of pixels directly from disk, having figured out the file format.
For compressed formats, you will need to decompress the image first. For example, for PNG and the GD library, the GD function imagecreatefrompng()
does not document direct access to the memory area where the pixel data of the resulting imageresource is stored. Therefore, with it, the only option is to iterate in a loop.
See what ImageMagick can do . For example getImageColors()

O
Oleg, 2020-02-28
@402d

There is no equivalent function in PHP to take all the pixels from an image area as a 32-bit integer.
First of all, it's gluttonous from memory. secondly, it is customary to do heavy calculations in the background.
Well, thirdly, for background tasks, it is easier to build processing with bash scripts.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question