3

I want to replace all white pixel from a completely white column with other color and if I have a black pixel on column don't change anything, but I don't know where is the problem...

Here is the code:

function findLines() {
    $blank = 1;
    $im_1 = imageCreateFromPng('resize_1.png');
    for($i=0; $i<1090; $i++) {
        if($blank == 1) {
            for($j=0; $j<240; $j++) {
                $rgb = imageColorAt($im_1, $i, $j);
                $r = ($rgb >> 16) & 0xFF;
                $g = ($rgb >> 8) & 0xFF;
                $b = $rgb & 0xFF;
                $c = $r.$g.$b;
                if($c === "0 0 0") {
                    $blank = 0;
                }
                $color = imageColorAllocate($im_1, 0, 255, 255);    
                imageSetPixel($im_1, $i, $j, $color);
            }
        }
        if ($blank == 0) {
            for($j=0; $j<240; $j++) {
                $rgb = imageColorAt($im_1, $i, $j);
                $r = ($rgb >> 16) & 0xFF;
                $g = ($rgb >> 8) & 0xFF;
                $b = $rgb & 0xFF;
                $c = $r . " " . $g . " " . $b;
                if($c === "255 255 255") {
                    $blank = 1;
                }


            }
        } else {
            $blank = 0;
        }
    } 
    header("Content-Type: image/png");
    imagepng($im_1);
}
likeitlikeit
  • 5,563
  • 5
  • 42
  • 56
Alex F
  • 41
  • 3

1 Answers1

1

This is the right one. Thanks anyway!

function findLines() {
    $im_1 = imageCreateFromPng('resize_1.png');
    for($i=0; $i<1090; $i++) {
        $blank = 1;
        for($j=0; $j<240; $j++) {
            $rgb = imageColorAt($im_1, $i, $j);
            if($rgb == 0) {
                $blank = 0;
            }
        }
        if ($blank == 1) {
            for($j=0; $j<240; $j++) {
                $color = imageColorAllocate($im_1, 155, 155, 155);  
                imageSetPixel($im_1, $i, $j, $color);
            }
        } else {
            $blank = 0;
        }
    }
    header("Content-Type: image/png");
    imagepng($im_1);
}
Alex F
  • 41
  • 3