In diesem PHP Snippet von Sick^ seht ihr, wie ein Bild nach einer bestimmten Farbe durchsucht werden kann.
C
- // url of image
- $img_url = 'http://localhost/text.jpg';
- // create image resource
- $img = imagecreatefromjpeg($img_url);
- // setup search color
- $search_color = imagecolorallocate($img, 255, 255, 255);
- $width = imagesx($img);
- $height = imagesy($img);
- // loop throught the image
- for ($x = 0; $x < $width; $x++) {
- for ($y = 0; $y < $height; $y++) {
- // get current pixel
- $cur_color = imagecolorat($img, $x, $y);
- // compare current pixel with searched pixel
- if ($cur_color == $search_color) {
- print "Color ". strtoupper(dechex($search_color)) ." found at X: $x; Y: $y\n";
- }
- }
- }
Termi